How To Display Previous/Next Post in Category?

By default you see next/previous post link in your theme by publishing date. If you want to display link to previous/next post from same category, you can use following code with in your loop. For eexample you have a category "How to create a WordPress Theme" and you want to display links to something like following You can add following code in your wordpress theme's single.php file.
 
<p>This entry posted in <?php the_category(','); ?> series. Show all in <?php the_category(','); ?>   </p>

<ul class="pager">
  <li class="previous">
    <?php previous_post_link('%link', 'Previous in Series', TRUE); ?>
  </li>
  <li class="next">
    <?php next_post_link('%link', 'Next in Series' , TRUE); ?>
  </li>
</ul> 
 
. I have added above code in my themes single.php file and after adding above code single.php looks like following.
 
  <?php
/**
 * @package TaousDesign
 * @since TaousDesign 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <header class="entry-header">
  <h1 class="entry-title"><?php the_title(); ?></h1>

  <div class="entry-meta">
   <?php taousdesign_posted_on(); ?>

    <?php edit_post_link( __( 'Edit', 'taousdesign' ), '<span class="sep"> | </span><span class="edit-link">', '</span>' ); ?>
  </div><!-- .entry-meta -->
 </header><!-- .entry-header -->
  
  

 <div class="entry-content">

  <p>This entry posted in <?php the_category(','); ?> series. Show all in <?php the_category(','); ?>   </p>

  <ul class="pager">
    <li class="previous">
      <?php previous_post_link('%link', 'Previous in Series', TRUE); ?>
    </li>
    <li class="next">
      <?php next_post_link('%link', 'Next in Series' , TRUE); ?>
    </li>
  </ul> 

  <?php the_content(); ?>

  <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'taousdesign' ), 'after' => '</div>' ) ); ?>
 </div><!-- .entry-content -->

 <footer class="entry-meta">
  <?php
   /* translators: used between list items, there is a space after the comma */
   $category_list = get_the_category_list( __( ', ', 'taousdesign' ) );

   /* translators: used between list items, there is a space after the comma */
   $tag_list = get_the_tag_list( '', ', ' );

   if ( ! taousdesign_categorized_blog() ) {
    
   } else {
    // But this blog has loads of categories so we should probably display them here
    if ( '' != $tag_list ) {
     $meta_text = __( 'Tags :  %2$s.', 'taousdesign' );
    } else {
    }

   } // end check for categories on this blog

   printf(
    $meta_text,
    $category_list,
    $tag_list,
    get_permalink(),
    the_title_attribute( 'echo=0' )
   );
  ?>

  <?php edit_post_link( __( 'Edit', 'taousdesign' ), '<span class="edit-link">', '</span>' ); ?>
 </footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->

 
. I hope this will word for you too. Note: i am using twitter bootstrap for styling. .pager is twitter bootstrap class for pagination styling.

Related Posts:

  • BitSpirit - Torrent ClientBitSpirit is a powerful and easy to use BitTorrent client whichprovides not only full BitTorrent protocol implementation but alsomany personalized features. It supports simultaneous downloads,download queue, UPNP portmaping, … Read More
  • 128GB USB Flash Drive from KingstonDataTraveler 200Space, speed & security.Kingston's new DataTraveler® 200 USB Flash drive is ideal for storing and transferring digital images and presentations and transporting all kinds of data. With capacities up to 128GB, … Read More
  • KINGSTON BOOSTS DATATRAVELER CAPACITY TO 64GBKingston Technology Company, Inc., the independent world leader in memory products,recently announced it is shipping its high-capacity 64GB DataTraveler 150 (DT150) USB Flash drive. DT150 offers the largest capacity in Kingst… Read More
  • Kingston unleashed world's 1st 256GB USB Flash driveDataTraveler 300World's first 256 GB USB Flash driveKingston's new DataTraveler® 300 USB Flash drive carries the highest capacity available on the market. Up to 90% of the drives content can be password protected and conveni… Read More
  • Google Transliteration now Available in Urdu and PunjabiGoogle recently added Urdu and Punjabi support to Transliteration service.Transliteration allows users to type words phonetically using their english keyboard. For example, in Urdu, you can type "shukriya" to get شکریہ and in… Read More

0 comments: