我在购买模板中有这首颂歌。我想知道要添加什么来获取类别的子名称
mais显示类别为赞助商。但在赞助商类别中,有:金、银、铂。。。我想得到“颜色”类别,并将其输出为<div class="cat-name">platium</div>
代码如下:
<div id="carouselContainer">
<h2 id="sponsorsTitle"><?php echo get_cat_name( $carouselCategory ) ?></h2>
<ul id="carousel">
<?php $showPostsInCategory = new WP_Query(); $showPostsInCategory->query(\'cat=\'. $carouselCategory .\'&showposts=\'. $carouselNumber .\'\');
if ($showPostsInCategory->have_posts()) : while ($showPostsInCategory->have_posts()) : $showPostsInCategory->the_post();?>
<li>
<?php $data = get_post_meta( $post->ID, \'key\', true ); ?>
<?php echo get_cat_name( $carouselCategory ) ?>
<a href="<?php if ($data[ \'custom_link\' ]) { echo $data[ \'custom_link\' ];} else { the_permalink(); } ?>">
<?php the_post_thumbnail(\'sponsor\', array(\'title\' => "")); ?>
</a>
</li>
<?php endwhile; endif; ?>
</ul><!--end carousel-->
</div><!--end carouselContainer-->
<?php } ?>
<div id="footerContainer">
<div id="footer">
SO网友:menardmam
<?php
function get_me_the_child_cat($arr, $val){
foreach ($arr as $key => $value){
if ($arr[$key] == $val){
unset($arr[$key]);
}
}
$arr_clean = array_values($arr);
return (get_cat_name( $arr_clean[0]));
}
?>
<div class="clear"></div>
</div><!--end content-->
</div><!--end contentContainer-->
<div id="carouselContainer">
<h2 id="sponsorsTitle"><?php echo get_cat_name( $carouselCategory ) ?></h2>
<div id="carousel">
<ul>
<?php $showPostsInCategory = new WP_Query(); $showPostsInCategory->query(\'cat=\'. $carouselCategory .\'&showposts=\'. $carouselNumber .\'\');
if ($showPostsInCategory->have_posts()) : while ($showPostsInCategory->have_posts()) : $showPostsInCategory->the_post();?>
<li class="spacerli">
<?php $data = get_post_meta( $post->ID, \'key\', true ); ?>
<div class="headerlogo"><?php $all_cat = wp_get_post_categories($post->ID); echo (get_me_the_child_cat($all_cat,$carouselCategory));?></div>
<a href="<?php if ($data[ \'custom_link\' ]) { echo $data[ \'custom_link\' ];} else { the_permalink(); } ?>">
<?php the_post_thumbnail(\'sponsor\', array(\'title\' => "")); ?>
</a>
</li>
<?php endwhile; endif; ?>
</ul>