Advertisement
amitverm

Map Categories to Pages Pagination

Aug 31st, 2011
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <? /* List posts from the same categories - start */
  2.         global $post;
  3.         $cats=array();
  4.         foreach(get_the_category() as $category) {
  5.             $cats[]=$category->cat_ID;
  6.         }
  7.         $showposts = 1; // -1 shows all posts
  8.         $do_not_show_stickies = 1; // 0 to show stickies
  9.         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  10.         $args=array(
  11.             'category__in' => $cats,
  12.             'caller_get_posts' => $do_not_show_stickies,
  13.             'posts_per_page'    =>  1,
  14.             'paged' => $paged
  15.         );
  16.         $temp = $wp_query;  // assign orginal query to temp variable for later use  
  17.         $wp_query = null;
  18.         $wp_query = new WP_Query($args);
  19.         while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  20.           <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  21.             <header>
  22.               <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  23.                 <?php the_title(); ?>
  24.                 </a></h2>
  25.               <?php if ( 'post' == get_post_type() ) : ?>
  26.               <div class="entry-meta">
  27.                 <?php twentyeleven_posted_on(); ?>
  28.               </div>
  29.               <!-- .entry-meta -->
  30.               <?php endif; ?>
  31.             </header>
  32.             <!-- .entry-header -->
  33.             <div class="entry-summary">
  34.               <?php the_excerpt(); ?>
  35.             </div>
  36.             <!-- .entry-summary -->
  37.           </article>
  38.   <!-- #post-<?php the_ID(); ?> -->
  39.   <?php endwhile; ?>
  40.   <div class="navigation">
  41.     <div class="alignleft">
  42.       <?php next_posts_link('« Older Entries') ?>
  43.     </div>
  44.     <div class="alignright">
  45.       <?php previous_posts_link('Newer Entries »') ?>
  46.     </div>
  47.   </div>
  48.   <?php $wp_query = $temp;  //reset back to original query ?>
  49.   <?php /* List posts from the same categories - end */?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement