分页的Author.php不使用Author.php模板

时间:2017-07-31 作者:Sylar

我创造了一个作家。php显示作者的帖子,并分页。单击“下一步”按钮时,我会进入第二页,但使用的模板不同。有什么原因吗?

My query in author.php

$curauth = (get_query_var(\'author_name\')) ? get_user_by(\'slug\', get_query_var(\'author_name\')) : get_userdata(get_query_var(\'author\'));
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$args = array(
  \'author\'        =>  $curauth->ID,
  \'orderby\'       =>  \'post_date\',
  \'order\'         =>  \'DSC\',
  \'paged\'         => $paged,
  \'post_type\' => \'post\',
  \'posts_per_page\' => 1, // there are more
  );

  $authors_posts = new WP_Query( $args );

Links:

<?php echo get_next_posts_link( \'Next\', $authors_posts->max_num_pages ); ?>
<?php echo get_previous_posts_link( \'Previous\' ); ?>

1 个回复
SO网友:Nuno Sarmento

这不是为您的问题修复的,只是您可以为作者使用的一个工作示例。php页面。

<?php 
 $number   = 10;
 $paged    = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
 $offset   = ($paged - 1) * $number;
 $users    = get_users();
 $query    = get_users(\'&offset=\'.$offset.\'&number=\'.$number);
 $total_users = count($users);
 $total_query = count($query);
 $total_pages = intval($total_users / $number) + 1;

 echo \'<ul id="users">\';

 foreach($query as $q) { ?>

 <li class="user clearfix">
   <div class="user-avatar">
    <?php echo get_avatar( $q->ID, 80 ); ?>  
  </div>
  <div class="user-data">

  <h4 class="user-name">
    <a href="<?php echo get_author_posts_url($q->ID);?>">
      <?php echo get_the_author_meta(\'display_name\', $q->ID);?>
    </a>
  </h4>

     <?php if (get_the_author_meta(\'description\', $q->ID) != \'\') : ?>
    <p><?php echo get_the_author_meta(\'description\', $q->ID); ?></p>
    <?php endif; ?>

   </div>
  </li>

  <?php } 

  echo \'</ul>\';

?>

<?php
  if ($total_users > $total_query) {
  echo \'<div id="pagination" class="clearfix">\';
  echo \'<span class="pages">Pages:</span>\';
  $current_page = max(1, get_query_var(\'paged\'));
  echo paginate_links(array(
  \'base\' => get_pagenum_link(1) . \'%_%\',
  \'format\' => \'page/%#%/\',
  \'current\' => $current_page,
  \'total\' => $total_pages,
  \'prev_next\'    => false,
  \'type\'         => \'list\',
  ));
  echo \'</div>\';
?>
您还需要调整css类以匹配您的主题样式

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post