wordpress 中具有相同父级的帖子的下一个/上一个链接 [英] Next/Prev links for posts with same parent in wordpress

查看:22
本文介绍了wordpress 中具有相同父级的帖子的下一个/上一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为具有相同父帖子(非类别)的帖子创建上一个/下一个链接?

How to create previous/next links for posts with the same parent post (not category)?

与此类似:

$previous_post = get_adjacent_post( true, '', true);

但是对于具有相同父级的帖子.

but for posts with the same parent.

推荐答案

我猜你在谈论页面.

因此您需要声明父页面,然后使用 get_pages 调用其他页面.

so you would need to declare the parent then use get_pages to call the other pages.

所以在你的循环中:

<?php $parent = $post->post_parent; $pagelist = get_pages('post_type=page&sort_column=menu_order&sort_order=desc&child_of='.$parent); $pages = array(); foreach ($pagelist as $page) {$pages[] += $page->ID;}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<?php if (!empty($prevID)) { ?>
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>"><?php echo get_the_title($prevID); ?></a>
<?php }
if (!empty($nextID)) { ?>
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?></a>
<?php } ?>

这篇关于wordpress 中具有相同父级的帖子的下一个/上一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆