【问题标题】:Wordpress Pagination on static homepage静态主页上的 Wordpress 分页
【发布时间】:2016-09-25 17:37:18
【问题描述】:

我正在尝试让 Pagination 在我与 wordpress 集成的静态主页上工作。我遇到的问题是,当我单击页面上的“旧条目”按钮时,它会转到 ?paged=2 页面,但仍显示前 10 个帖子。就像在第一页上一样。

我知道代码有些工作,因为我将 ($the_query->max_num_pages > 1) 更改为 2 并转到该页面,它显示了带有“新条目”按钮的第二页的内容。

我就是无法让它自动完成。

我使用了这个人的教程来了解如何设置它 http://callmenick.com/post/custom-wordpress-loop-with-pagination

这是我的代码

<?php
  // set up or arguments for our custom query
  $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
  $query_args = array(
    'post_type' => 'post',
    'paged' => $paged
  );
  // create a new instance of WP_Query
  $the_query = new WP_Query( $query_args );
?>

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
  <article>
    <h1><?php echo the_title(); ?></h1>
    <div class="excerpt">
      <?php the_excerpt(); ?>
    </div>
  </article>
<?php endwhile; ?>

<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
  <nav class="prev-next-posts">
    <div class="prev-posts-link">
      <?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
    </div>
    <div class="next-posts-link">
      <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
    </div>
  </nav>
<?php } ?>

<?php else: ?>
  <article>
    <h1>Sorry...</h1>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  </article>
<?php endif; ?>

网站(临时)可以在这里看到http://auroraservers.org/MainSite/Index.php

所以你可以看到它在做什么。

感谢您的帮助!我已经尝试解决这个问题超过一天了,所以我希望它不会太麻烦。

【问题讨论】:

  • 欢迎来到 SO, 3253191。请尽量只为您的问题使用相关标签。我是从CSS 问题堆栈中提出您的问题的,它与CSS 无关。
  • 哦,对不起,我整天都在做一些事情,并且把一些我最近正在做的事情放在了我的脑海中。不会再发生了!我保证!

标签: php wordpress pagination


【解决方案1】:

这一行应该是paged 而不是page

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

【讨论】:

  • 旧版本的WP确实使用page作为query_var。有一段时间,我们实际上不得不检查两者并获取填充的任何一个,如果有的话。显然,他遇到了一个过时的教程。很好的发现!
  • 哦,感谢您提供的那一点信息以及对我问题的解答!作为一名初级 Web 开发人员,我正在努力了解这样的事情是如何工作的:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-09
  • 2023-03-07
  • 2019-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多