我想在所有的帖子(single.php)中显示一个证书代码,这是与一个父亲猫的所有子猫相关联的。我想要的代码工作的所有这篇文章谁是下这个子猫(下的主要猫)
我试过这样做:
<?php function get_child_cats( $catname ) {
$parentcat = get_cat_ID(8);
$subcat = get_categories( array('child_of' => $parentcat ) );
$cat_array = array();
array_push($cat_array, $parentcat); // add the parent cat to the array
foreach ($subcat as $sc) {
array_push($cat_array, $sc->cat_ID);
}
return $cat_array;
}?>还有这个:
<?php if (in_category(8) && !is_feed()) { ?>发布于 2014-02-01 17:01:06
它是这样做的:
<?php $mycats = array(8);
foreach (get_the_category() as $childcat) {
foreach ($mycats as $mycat) {
if (cat_is_ancestor_of($mycat, $childcat)) { ?>
<ul> <?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=8'); ?></ul>
<?php break 2;
}
}
} ?>https://stackoverflow.com/questions/21485726
复制相似问题