post_nav_link导航可以与WordPress自定义页面模板一起使用吗? [英] Can post_nav_link navigation work with WordPress custom page templates?
问题描述
我正在使用自定义页面模板来构建我想出售的WordPress主题中的不同博客布局.除了post_nav_link导航(上一篇文章|下一篇文章)之外,其他所有功能都正常运行. Wordpress Codex说post_nav_links不适用于自定义页面模板,但是我真的不想从头开始.我可以做些什么来使post_nav_link导航与自定义页面模板一起使用?
I am using custom page templates to structure different blog layouts in my WordPress theme that I want to sell. Everything is functioning fine except the post_nav_link navigation (previous post | next post). The wordpress codex says that post_nav_links won't work with custom page templates, but I really don't want to start all over again. Is there anything I can do to make post_nav_link navigation work with custom page templates?
Codex推荐人: http://codex.wordpress.org/Next_and_Previous_Links
Codex Refernece: http://codex.wordpress.org/Next_and_Previous_Links
推荐答案
尝试一下,它适用于我的自定义模板,您可能需要向query_posts
添加args,但是键是偏移量.
Try this, it works for my custom template, you might need to add args to query_posts
but the key is an offset.
$paged = get_query_var('paged');
$offset = 0;
if ($paged != 0 ) {
//$paged -1 because there is no page 1, just 0 and 2 And page 0 is skipped
$offset = ($paged-1) * get_query_var('posts_per_page') ;
}
query_posts('offset=' . $offset);
if (have_posts()) : while (have_posts()) : the_post();
// the loop
并用于分页:
<div id="pagination">
<div id="pagination-previous"><?php previous_posts_link('previous'); ?></div>
<div id="pagination-next"><?php next_posts_link('next'); ?></div>
</div>
这篇关于post_nav_link导航可以与WordPress自定义页面模板一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!