如果父母秀...... ElseIf儿童秀......在同一页面上?

时间:2012-02-01 16:35:51

标签: php

我有一个自定义帖子类型的'编辑器',工作正常。

每个帖子类型都会有主编辑父母的各种子帖。

在single-editors.php页面上,如果它是PARENT,我需要它显示x内容,但是如果它的CHILD显示完全不同的内容并且显然忽略任何父内容。

这就是我到目前为止“工作”的内容,它显示了父页面上的内容,但后来在子页面上没有显示任何内容。

<?php get_header(); ?>

<!-- IF Parent Show Below -->

 <?php $this_page_id=$wp_query->post->ID; ?>

<?php query_posts(array('showposts' => 1, 'post_parent' => $this_page_id, 'post_type' => 'editors')); while (have_posts()) { the_post(); ?>


<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>


<?php } ?>

<!-- IF Child Show Below ignore the above -->

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<section role="document">

<?php the_content(); ?>

</section>

<?php endwhile; endif; ?>


<?php get_footer(); ?>

我不擅长条件,所以我想知道它是否可能?显然,自定义帖子的所有内容都必须出现在single-editors.php

1 个答案:

答案 0 :(得分:0)

if ($post->post_parent == 0) {
    // has no parent, is parent
    get_template_part('single-editors', 'parent');
    } else {
    // child
    get_template_part('single-editors', 'children');
    }
如果您有超过2个级别(如parent-&gt; child-&gt; child),

将无效。

相关问题