WordPress育儿问题

时间:2014-07-19 23:18:16

标签: wordpress wordpress-theming parent-child

我有以下

GrandParent
-Parent01
--Child
-Parent02
--Child
--Child
-Parent03
--Child

我希望找到一个解决方案,当我在祖父母页面上,它只会返回父母,而不是孩子IE。

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>

1 个答案:

答案 0 :(得分:1)

假设$heading_page->post_id$postid = the_post_ID();的值相同,您可以检查循环中的post_parent属性和continue当它们不匹配时:

<?php foreach ( $pages as $page ): ?>
<?php if ( $postid != $page->post_parent ) continue; ?>