Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

ShootingStar83 on "child-of [x] category in CURRENT post"

$
0
0

I found this code to show sub categories of [x] category and I like it, I just need to make it working as "Show sub-categories of [x] category IN CURRENT POST" because I'm going to paste this code in a widget inside posts only.

<?php
$subcategories = get_categories('&child_of=4&hide_empty'); // List subcategories of category '4' (even the ones with no posts in them)
echo '<ul>';
foreach ($subcategories as $subcategory) {
  echo sprintf('<li><a href="%s">%s</a></li>', get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));
}
echo '</ul>';
?>

What is the code that will apply this code to the post the visitor is reading?

Appreciate your help in advance.

Thank you


Viewing all articles
Browse latest Browse all 8245

Trending Articles