2012-03-18 169 views
1

我已经在wordpress中创建了一个称为“电影”的分层定制帖子类型。它是分层的,所以它可以有孩子的元素。WordPress的自定义帖子类型儿童模板

当单击“电影”时,wordpress会自动使用名为'single-films.php'的模板。这很好,但是我希望在点击某个电影的子页面时使用不同的模板。例如,电影的孩子可能是“新闻”。当单击该电影的媒体链接时,我希望它使用与单个films.php不同的模板。

我希望有一些方法可以使用像single-children-films.php这样的模板。任何想法如何我可以更改层次结构自定义帖子类型的子模板?

+0

或者,处理它是有条件的逻辑添加到单膜的另一种方式。 PHP的说,如果这个职位是父母,这样做...如果这个职位是一个孩子,这样做....但我不确定的鳕鱼e要做到这一点。 – JCHASE11 2012-03-18 16:39:16

+0

我刚刚在这里回答了非常类似的问题:https://stackoverflow.com/questions/45919508/allowed-template-for-children-wordpress/45922616#45922616 – Paul 2017-08-29 11:13:36

回答

0

我确定我可以帮忙。我只需要知道一件事,孩子总是和父母一样的职位类型吗?或者就像你在你的例子中说的那样“按”它自己的单独的自定义文章类型?

1

我想我刚才做同样的事情:

我有一个自定义后类型,称为“产品”的父母是“品牌”和孩子本质上是一种“品牌项目”这里是什么我把我的单product.php

这是第一个查询来获取孩子的帖子[项目]

<?php $mypages = get_pages(array('child_of' => $post->ID, 'post_type' => 'product', 'sort_order' => 'desc')); 
//So if it is not a parent 
if (empty($mypages)){ ?> 
//use these styles 
<div class="single_item">stuff is happening</div> 
//If it is a parent post so has children 
<?php ; } else { ?> 
//Then Do these things 
<div class="brandstuff">showing extra stuffs</div> 
<div class="morebrandstuffs">maybe do some extra stuff</div> 
//I wanted to add a list of my child pages to my parent page 
<?php $mypages = get_pages(array('child_of' => $post->ID, 'post_type' => 'product', 'sort_order' => 'desc')); 

foreach($mypages as $page) {  
    $content = $page->post_content; 
    if (! $content) // Check for empty page 
     continue; 

    $content = apply_filters('the_content', $content); 
?><div class="item"> 
    <a href="<?php echo get_permalink($page->ID); ?>"> 
    <div class="item_thumb"><?php echo get_the_post_thumbnail($page->ID, 'item_thumb'); ?></div> 
    <?php echo $page->post_title; ?></a> 
     </div> 

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