Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 育儿问题_Wordpress_Wordpress Theming_Parent Child - Fatal编程技术网

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; ?>