Wordpress 育儿问题
我有以下几点Wordpress 育儿问题,wordpress,wordpress-theming,parent-child,Wordpress,Wordpress Theming,Parent Child,我有以下几点 GrandParent -Parent01 --Child -Parent02 --Child --Child -Parent03 --Child 我希望找到一个解决办法,当我在祖父母页面上时,它只会返回父母,而不会返回孩子 GrandParent -Parent01 -Parent02 -Parent03 这是我目前拥有的代码,它生成祖父母页面的所有父母和孩子,并将他们放在一个表中 <?php $postid = get_the_ID(); ?> <?ph
GrandParent
-Parent01
--Child
-Parent02
--Child
--Child
-Parent03
--Child
我希望找到一个解决办法,当我在祖父母页面上时,它只会返回父母,而不会返回孩子
GrandParent
-Parent01
-Parent02
-Parent03
这是我目前拥有的代码,它生成祖父母页面的所有父母和孩子,并将他们放在一个表中
<?php $postid = get_the_ID(); ?>
<?php /* $pages = get_pages(array('child_of' =>$postid)); */
$pages = get_children(array(
'numberposts' =>30,
'post_parent' => $heading_page->post_id
));
$tCount= 0;
?>
<table align="center" width="100%"><tr>
<?php foreach ($pages as $page): ?>
<?php if($tCount % 2 == 0)
{
echo '</tr><tr>';
}?>
<td>
<div id="polaroid">
<figure>
<a href="<?php echo get_permalink($page->ID); ?>">
<?php echo get_the_post_thumbnail($page->ID, array(300,250)); ?></a>
<figcaption>
<a href="<?php echo get_permalink($page->ID); ?>"><?php echo $page- >post_title ?>
</a></figcaption>
</figure>
</div>
</td>
<?php $tCount++; endforeach; ?>
</tr></table>
假设
$heading\u page->post\u id
和$postd=post\u id()
值相同,您只需检查循环中的post\u parent
属性,当它们不匹配时,continue
:
<?php foreach ( $pages as $page ): ?>
<?php if ( $postid != $page->post_parent ) continue; ?>