Shoora
4/22/2019 - 10:12 AM

WordPress Snippets

WordPress Snippets

<?php /* Template Name: Sitemap */ get_header(); ?>

<div class="sitemap">

        <h1 class="title">Sitemap</h1>  

        <div class="sitemap-loop-posts">
                
                <h2 class="subtitle">Posts</h2>

                <?php $sitemaploopposts = new WP_Query( array( 
                        'post_type' => 'post', 
                        'posts_per_page' => -1, 
                        'post_status' => 'publish' 
                ));?>

                <?php while ( $sitemaploopposts->have_posts() ) : $sitemaploopposts->the_post(); ?>

                        <a href="<?php echo get_permalink($post->ID); ?>" rel="dofollow" title="<?php the_title(); ?>">
                                <?php the_title(); ?>
                        </a>

                <?php endwhile; ?>

                <?php wp_reset_query(); ?>

        </div><!-- sitemap-loop-posts -->

        <div class="sitemap-loop-pages">

                <h2 class="subtitle">Pages</h2>                 
                
                <?php $sitemaplooppages = new WP_Query( array( 
                        'post_type' => 'page', 
                        'posts_per_page' => -1, 
                        'post_status' => 'publish' 
                ));?>

                <?php while ( $sitemaplooppages->have_posts() ) : $sitemaplooppages->the_post(); ?>

                        <a href="<?php echo get_permalink($post->ID); ?>" rel="dofollow" title="<?php the_title(); ?>">
                                <?php the_title(); ?>
                        </a>
                
                <?php endwhile; ?>

                <?php wp_reset_query(); ?>

                </div><!-- sitemap-loop-pages -->

<!-- 
   Start: WooCommerce Sitemap Products Loop
   Delete this section if you are not using WooCommerce 
-->

        <div class="sitemap-loop-woocommerce-products">

                <h2 class="subtitle">Products</h2>                
                
                <?php $sitemaploopproducts = new WP_Query( array( 
                        'post_type' => 'product', 
                        'posts_per_page' => -1, 
                        'post_status' => 'publish' 
                ));?>

                <?php while ( $sitemaploopproducts->have_posts() ) : $sitemaploopproducts->the_post(); ?>

                <a href="<?php echo get_permalink($post->ID); ?>" rel="dofollow" title="<?php the_title(); ?>">
                        <?php the_title(); ?>
                </a>

                <?php endwhile; ?>

                <?php wp_reset_query(); ?>

        </div><!-- sitemap-loop-woocommerce-products -->
        
<!-- 
End: WooCommerce Sitemap Products Loop
Delete this section if you are not using WooCommerce 
-->
        
        <!-- Delete this credit if you want -->
        <p>Free sitemap powered by <a href="https://codesauce.co.uk/" rel="dofollow" target="_blank">Codesauce</a></p>

</div><!-- .sitemap -->

<?php get_footer(); ?>