You are on page 1of 3

============================================

Display recent posts with pagination on page


============================================
Note: Paste the codes in your custompage.php
'posts_per_page' => 10 or 'posts_per_page' => 5 ect..
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 10, 'paged' =>
$paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ?></h2>
<?php endwhile; ?>
<!-- then the pagination links -->
<?php next_posts_link( '&larr; Older posts' ); ?>
<?php previous_posts_link( 'Newer posts &rarr;' ); ?>
EX:
<main id="main" class="site-main col-sm-9 col-md-9 blog-entries" role="main">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 5, 'paged' =>
$paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); ?>
<div class="row">
<div class="col-sm-4 col-md-4">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<div class="col-sm-8 col-md-8">
<h4><a href="<?php echo get_permalink(); ?>"><?p
hp the_title(); ?></a></h4>
<p class="entry-meta"><?php billiant_designs_pos
ted_on(); ?> by <?php the_author_posts_link(); ?></p>
<?php the_content_limit(130); ?>
</div>
</div>
<?php endwhile; ?>
<!-- then the pagination links -->
<?php next_posts_link( '&larr; Older posts' ); ?>
<?php previous_posts_link( 'Newer posts &rarr;' ); ?>
</main><!-- #main -->
http://codex.wordpress.org/Pagination
------------------------------------<?php
// the query to set the posts per page to 3
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3, 'paged' => $paged );
query_posts($args); ?>

<!-- the loop -->


<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<!-- rest of the loop -->
<!-- the title, the content etc.. -->
<?php endwhile; ?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>

=======================================
Display recent posts without pagination
=======================================
<main id="main" class="site-main col-sm-9 col-md-9 blog-entries" role="main">
<?php query_posts('cat=#&posts_per_page=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-4 col-md-4">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<div class="col-sm-8 col-md-8">
<h4><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></
h4>
<p class="entry-meta"><?php billiant_designs_posted_on(); ?> by <?php ec
ho get_the_author_link(); ?></p>
<?php the_content_limit(150); ?><!--this needs a plugin-->
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</main><!-- #main -->

======================================================
Display the Most Recent Posts from a Specific Category
======================================================
The code below will show 1 post with the excerpt from category 3:
<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?><
/a></h3>
<ul><li><?php the_excerpt(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

To only show links from the category use the code below:
<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?><
/a></h3>
</li>
</ul>
<?php endwhile; ?>

You might also like