Advertisement
getakter

Display Blog Posts on any Page (with navigation)

Sep 23rd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. /*
  3.     Template Name: Blog
  4. */
  5. ?>
  6. <?php get_header(); ?>
  7.  
  8.     <article>
  9.  
  10.         <?php // Display blog posts on any page @ http://m0n.co/l
  11.         $temp = $wp_query; $wp_query= null;
  12.         $wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
  13.         while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  14.  
  15.         <h2><a href="<?php the_permalink(); ?>" title="Read more"><?php the_title(); ?></a></h2>
  16.         <?php the_excerpt(); ?>
  17.  
  18.         <?php endwhile; ?>
  19.  
  20.         <?php if ($paged > 1) { ?>
  21.  
  22.         <nav id="nav-posts">
  23.             <div class="prev"><?php next_posts_link('&laquo; Previous Posts'); ?></div>
  24.             <div class="next"><?php previous_posts_link('Newer Posts &raquo;'); ?></div>
  25.         </nav>
  26.  
  27.         <?php } else { ?>
  28.  
  29.         <nav id="nav-posts">
  30.             <div class="prev"><?php next_posts_link('&laquo; Previous Posts'); ?></div>
  31.         </nav>
  32.  
  33.         <?php } ?>
  34.  
  35.         <?php wp_reset_postdata(); ?>
  36.  
  37.     </article>
  38.  
  39. <?php get_footer(); ?>
  40.  
  41. //Reference http://digwp.com/2013/01/display-blog-posts-on-page-with-navigation/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement