wordpress分页没有显示

时间:2016-11-08 09:29:39

标签: wordpress pagination

****** ******* EDIT

这是我的帖子代码:

<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
query_posts('posts_per_page=3&paged=' . $paged);
  $args = array (
    'posts_per_page' => 3,
    $offset = $paged*$pages,
    'post_type' => array('post','project'),
    'meta_key' => '_thumbnail_id'
  );

带数字的导航显示,他转到第2页,但新帖子没有显示。

我构建了一个本地Wordpress网站进行测试。我在Wordpress中添加分页。但是,分页不会出现。这是我的代码:

 $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  $args = array (
    'posts_per_page' => 3,
    'offset' => 0,
    'post_type' => array('post','project'),
    'meta_key' => '_thumbnail_id',
    'paged' => $paged
  )

  $home_recent = new WP_Query( $args );
  if( $home_recent ->have_posts() ) :
  while( $home_recent ->have_posts() ) :
  $home_recent ->the_post();
  $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); 
  $post_type = get_post_type( $post->ID ); ?>

这是为了获取帖子。

这是我的功能:

 function pagination($pages = '', $range = 4)
 {  
 $showitems = ($range * 2)+1;  

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
     global $wp_query;
     $pages = $wp_query->max_num_pages;
     if(!$pages)
     {
         $pages = 1;
     }
 }   

 if(1 != $pages)
 {
     echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
     if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
     if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

     for ($i=1; $i <= $pages; $i++)
     {
         if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
         {
             echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
         }
     }

     if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
     if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
     echo "</div>\n";
 }
  }

这表明了分页:

  <?php }
  endwhile;
  if (function_exists("pagination")) {
  pagination($additional_loop->max_num_pages);
  } 

  endif; wp_reset_postdata(); ?>

Butt它只显示了三个帖子。这个代码是错的还是我想念的东西?

儒略

0 个答案:

没有答案