【发布时间】: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