【发布时间】:2016-02-25 14:44:56
【问题描述】:
我现在非常了解 javascript,但我对 php 和 wordpress 主题构建还很陌生。我进行了相当多的搜索,但找不到解决看似非常简单的任务的解决方案,我想要完成的只是获取页面的所有孙子,而不是直接子孙,如下所示:
投资组合
- 孩子 1
- 孙子1A
- 孙子 1B
- 孩子 2
- 孙子2A
- 孙子2B
我的页面是“Portfolio”,我想“get_pages”,但只返回“Portfolio”的孙子页面,所以在这种情况下,它只会返回:-“grandchild 1A”、“grandchild 1B”、“grandchild” 2A”、“孙子 2B”。
<?php
$portfolio = get_pages( array(
'child_of' => $post->ID));
foreach( $portfolio as $page ) {
//My idea here was to check if the page that is being looped through, was a direct child of portfolio, if so then it would skip it.
if($page !== 'child_of' => $post) {
echo $page->post_title;
}
}?>
有什么建议吗?
编辑:
<?php
$grandchildren = get_pages( array( 'child_of' => $portfolioPageId ) );
foreach( $grandchildren as $grandchild ) {
if($grandchild->post_parent != $portfolioPageId ){
echo $grandchild->post_title;
}}?>
【问题讨论】:
-
到目前为止你尝试过什么?请阅读How to Ask 了解有关编写高质量问题的一些提示。
-
好的,我更新了我目前的问题。
标签: php wordpress foreach wordpress-theming