WordPress:next_posts_link() 在页面模板循环之前不起作用
我构建了一个存档页面模板,该模板在循环结束时可以成功导航。但是,现在我想在顶部添加额外的导航。但是,在我复制并粘贴确切的代码后,“上一个条目”会正确显示和链接,但“下一个条目”永远不会像底部导航中那样显示。
在我的 page-archive.php 文件中,这是我的代码要点:
<div class="navigation top">
<?php next_posts_link('Next Entries') ?> <!-- Doesn't appear to show up! -->
<?php previous_posts_link('Previous Entries') ?>
</div>
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=1&paged=$page");
while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h3><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></h3>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation bottom">
<?php next_posts_link('Next Entries') ?>
<?php previous_posts_link('Previous Entries') ?>
</div>
我知道页面模板不是创建存档页面的理想方法,因此如果有不同的方法来生成完全可定制的存档页面,请告知我!
目前,我使用 home.php 文件来显示静态内容,因此 page-archive.php 是一种将用户引导至网站实际“博客”部分的方法。
I have an archive page template that I've built that has a successful navigation at the end of the loop. However, now I want to add an additional navigation at the top. However, after I copied and pasted the exact code, the 'Previous Entries' displays and links correctly, but 'Next Entries' never shows up as it does in the bottom navigation.
In my page-archive.php file, this is gist of my code:
<div class="navigation top">
<?php next_posts_link('Next Entries') ?> <!-- Doesn't appear to show up! -->
<?php previous_posts_link('Previous Entries') ?>
</div>
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=1&paged=$page");
while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h3><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></h3>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation bottom">
<?php next_posts_link('Next Entries') ?>
<?php previous_posts_link('Previous Entries') ?>
</div>
I understand that a Page template is not the ideal method to create an archive page, so if there is a different method for producing a full customizable archive page, please inform me!
Currently, I'm using my home.php file to display static content, so the page-archive.php is a method to direct users to the actual "Blog" portion of the site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将此字符串:
放在页面的最顶部。您需要这样做,因为
next_posts_link
和prev_posts_link
调用使用query_posts
调用设置的一些全局变量。Try to put this string:
to the very top of the page. You need to do that because
next_posts_link
andprev_posts_link
calls use some global variables set byquery_posts
call.