views:

155

answers:

2

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?

A: 
adam
Thanks for the response. The ID of category Test1 is 2, I have checked it by hovering the link to edit category.
Permana
A: 

Is that category empty? By default WordPress hides emptr categories. try:

$categories =  get_categories('child_of=2&hide_empty=false');
LobsterMan
yes, there are no post have category Test1. I try adding hide_empty=false but it didn't work. I try the code on wordpress default theme, and also didn't workBut after I try using array parameter (not using string) it works. $categories = get_categories(array( 'child_of' => 4, 'hide_empty' => false));print_r($categories);Thanks for reminding me using hide_empty parameter
Permana