Advertisement
Guest User

Untitled

a guest
Sep 6th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php $idpost=0; ?>
  2. <?php global $paged;
  3. if ( get_query_var('paged') ) {
  4.     $paged = get_query_var('paged');
  5. } else if ( get_query_var('page') ) {
  6.     $paged = get_query_var('page');
  7. } else {
  8.     $paged = 1;
  9. }
  10. $args = array( 'post_type' => 'post', 'paged' => $paged );
  11.  
  12. $q = new WP_Query( $args );
  13.             ?>
  14. <?php if ($q->have_posts()) : ?>
  15. <?php while($q->have_posts()) : $q->the_post(); ?>
  16.  
  17. <?php if  (!is_paged()) { ?>
  18.     <li class="thum_<?php echo $idpost; ?>"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a><br />
  19.     <a class="sname" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
  20.     </li>
  21. <?php } else { ?>
  22.     <li class="thums_<?php echo $idpost; ?>"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a><br />
  23.     <a class="sname" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
  24.     </li>
  25. <?php } $idpost++; endwhile; ?>
  26.     </ul>
  27.     <div style="clear:both"></div>
  28.         <?php  if ( function_exists('wp_pagenavi') ) { ?>
  29.             <div id="wp-pagenavibox"><?php wp_pagenavi( array('query' => $q) ); ?></div>
  30.         <?php } endif; ?>
  31. <?php wp_reset_postdata(); ?>
  32.  
  33.  
  34. // in functions I am using
  35. function custom_posts_per_page($query) {
  36. if (is_home() && !is_paged()) {
  37.   $query->query_vars['posts_per_page'] = 8;
  38.   return $query;
  39.   } else {
  40.   $query->query_vars['offset'] = 8;
  41.   return $query;
  42.   }
  43. }
  44. add_filter('pre_get_posts', 'custom_posts_per_page');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement