gpt4 book ai didi

wordpress - 如何检索 Wordpress 页面的兄弟页面列表?

转载 作者:行者123 更新时间:2023-12-04 00:00:34 25 4
gpt4 key购买 nike

我正在尝试在 WordPress 中创建一个兄弟页面(不是帖子)列表来填充页面的侧边栏。我成功编写的代码返回页面的父标题。

<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title; ?>

据我了解,您需要一个页面的 id(而不是标题)来检索页面的 sibling (通过 wp_list_pages )。如何获取页面的父ID?

欢迎使用其他方法。目标是列出页面的 sibling ,不一定只是检索父级的 id。

最佳答案

$post->post_parent正在为您提供父 ID,$post->ID会给你当前的页面 ID。因此,以下将列出页面的 sibling :

wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID
))

关于wordpress - 如何检索 Wordpress 页面的兄弟页面列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2322271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com