Tiggles ツ
5/30/2019 - 1:07 PM

Display Blog Post on any template

want to create a custom blog page that contains your posts? This snippet will grab your posts and display them.

credit: https://m0n.co/l

<?php // Display blog posts on any page @ https://m0n.co/l
   $temp = $wp_query; $wp_query= null;
   $wp_query = new WP_Query(); $wp_query->query('posts_per_page=6' . '&paged='.$paged);
   while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
   <div class="single-post">
      <div class="post-image">
         <?php the_post_thumbnail() ?>
      </div>
      <div class="post-tags">
         <?php the_tags( '<ul><li>', '</li><li>', '</li></ul>' ); ?>
      </div>
      <h2 class="post-title">
         <a href="<?php the_permalink(); ?>" title="Read more"><?php the_title(); ?></a>
      </h2>
      <div class="post-snippet">
         <?php the_excerpt(); ?>
      </div>
      <a href="<?php the_permalink(); ?>" class="cta">Read More</a>
   </div>
      
      
  
   <?php endwhile; ?>
  
  <?php if ($paged > 1) { ?>
  
   <nav id="nav-posts">
      <div class="prev"><?php next_posts_link('&laquo; Previous Posts'); ?></div>
      <div class="next"><?php previous_posts_link('Newer Posts &raquo;'); ?></div>
   </nav>
  
  <?php } else { ?>
  
  <nav id="nav-posts">
    <div class="prev"><?php next_posts_link('&laquo; Previous Posts'); ?></div>
  </nav>
  
<?php } ?>
  
<?php wp_reset_postdata(); ?>