2012-03-19 36 views
0

我有一个自定义后类型,称为“薄膜”和大多数电影有一个子页(孩子)的页面循环。的WordPress只有通过有孩子或者所谓的“按”子页面

我通过电影试图循环,并检查是否存在子页面。如果存在子页面,则循环浏览内容,如果不存在,则省略内容。我的循环如下:

<?php $loop = new WP_Query(array('post_type' => 'films', 'posts_per_page' => 8,'orderby' => 'date', 'order' => 'ASC', 'film-categories' => 'available-now-shows-on-homepage')); ?> 

<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 

<?php while ($loop->have_posts()) : $loop->the_post(); ?> 

<?php endwhile; ?> 

我只希望链接标题显示它的页面是否有子页面(新闻页面)。我将如何修改循环来做到这一点?

回答

0

我只是想出了答案,以我自己的问题。它通过使用get_pages计数子页面的数量来工作。这里是工作代码:

<?php 
$children = get_pages(array('child_of' => $post->ID,'post_type'=>'custom-post-type-name')); 
if(count($children) != 0) { ?> 

<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 

<?php } 
else { } 
?> 
相关问题