Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get List of subcategory

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?

like image 918
Permana Avatar asked Jan 11 '10 08:01

Permana


1 Answers

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

like image 123
LobsterMan Avatar answered Sep 21 '22 01:09

LobsterMan