我正在尝试在 WordPress 中创建同级页面(不是帖子)列表来填充页面的侧边栏。我成功编写的代码返回页面父级的标题。
<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title; ?>
据我了解,您需要页面的 id(而不是标题)来检索页面的同级页面(通过wp_列表_页面 http://codex.wordpress.org/Template_Tags/wp_list_pages)。如何获取页面父级的 id?
欢迎使用替代方法。目标是列出页面的同级页面,而不必只是检索父页面的 id。
$post->post_parent
正在向您提供家长 ID,$post->ID
将为您提供当前页面 ID。因此,下面将列出页面的同级页面:
wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID
))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)