2012-02-01 90 views
1

我有一個自定義帖子類型的'編輯'它工作正常。如果家長顯示.... 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

感謝所有幫助:)

回答

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倍以上的水平(如

行不通父 - >孩子 - >孩子)。

+0

這似乎並沒有工作:( 似乎只顯示模板單編輯,children.php您是否父頁面或子頁面..?上 任何想法,感謝看着:) – Jezthomp 2012-02-02 09:19:34

+0

我也沒有得到這個工作。這將是一個理想的解決方案。 – user1167442 2015-01-11 15:15:30