如果家长显示.... ElseIf儿童显示...在同一页上?
问题描述:
我有一个自定义帖子类型的'编辑'它工作正常。如果家长显示.... ElseIf儿童显示...在同一页上?
每个帖子类型都会有主编辑器父项的各种子帖子。
在单editors.php页,我需要它来显示氧化物含量如果父,但如果孩子表现出完全不同的内容,显然忽略任何父内容...
这是我至今“作品”对于它显示了家长页面上的内容,但随后显示了子页面上也没有......
<?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(); ?>
我也不擅长条件语句,如果可能,所以我不知道。 ..?由于明显的自定义后的所有内容已经出现在单editors.php
感谢所有帮助:)
答
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倍以上的水平(如
行不通父 - >孩子 - >孩子)。
这似乎并没有工作:( 似乎只显示模板单编辑,children.php您是否父页面或子页面..?上 任何想法,感谢看着:) – Jezthomp 2012-02-02 09:19:34
我也没有得到这个工作。这将是一个理想的解决方案。 – user1167442 2015-01-11 15:15:30