【发布时间】:2015-12-19 12:46:52
【问题描述】:
我想在同一级别中添加下一页和上一页链接。
我在 WordPress 代码库中找到了适用于所有页面(子页面和父页面)的解决方案:https://codex.wordpress.org/Next_and_Previous_Links#The_Next_and_Previous_Pages
但我想要的是同一级别内的导航。
有什么办法解决这个问题吗?
编辑:
<?php
$pagelist = get_pages('post_type=publikation&sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$testPost = (get_pages( array( 'post_type' => 'publikation' ,'child_of' => $post->ID ) ) || $post->post_parent);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div class="navigation">
<?php if (!empty($prevID) && !$testPost) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID) && !$testPost) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"
title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div><!-- .navigation -->`
【问题讨论】:
标签: wordpress navigation