I have this category on my wordpress:
Test1
- Sub1OfTest1
- Sub2OfTest1
Test2
- Sub1OfTest2
- Sub2OfTest2
Now iam at url: http://localhost/wordpress/category/test1
I write the following code on file category-test1.php
<?php
$categories = get_categories('child_of=2');
print_r($categories);
foreach ($categories as $category) : ?>
<div class="qitem">
<a href="<?php get_category_link( $category->term_id ); ?>" title="<?php echo $category->name; ?>">
<?php echo $category->name; ?>
</a>
<h4>
<span class="caption">
<?php echo $category->name; ?>
</span>
</h4>
<p>
<span class="caption">
<?php echo $category->description; ?>
</span>
</p>
</div>
<?php
endforeach;
?>
I'm trying to show sub category of Test1 but the code only return array(). What did I miss?
Is that category empty? By default WordPress hides emptr categories. try:
$categories = get_categories('child_of=2&hide_empty=0');
Edit: Fixed, thank you @Stoep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With