1

My code is as follows:

$custom_args = array(
     'orderby'          => 'name',
     'order'            => 'ASC',   
     'depth'            => 1,
     'number'           => 4, 
);
    wp_list_categories($custom_args);

I'd like to create a list of categories and to show only the parent category, I use 'depth' => 1, but because I also want to control the number of categories, I added 'number' => 4 hoping that would be enough however it only shows one parent category.

If I remove depth it shows the 4 categories but the links are also children categories.

Any idea on how to solve this issue I'm having? Many thanks in advance.

  • Can your share your category hierarchy? i.e the structure of your parent and child categories. – Hareesh Sivasubramanian Oct 3 '15 at 17:52
0

Structure is as follows:

<ul class="main-menu">  
    <li><a href="">CMS Themes</a>
        <ul class="children">
            <li><a href="">Moodle</a></li>
        </ul>
    </li>
    <li><a href="">Empty Cat</a></li>
    <li><a href="">HTML</a>
        <ul class="children">
            <li><a href="">Creative</a></li>
        </ul>
    </li>
    <li><a href="">Photography</a></li>
    <li><a href="">Wordpress</a>
        <ul class="children">
            <li><a href="">Blog / Magazine</a></li>
            <li><a href="">Corporate</a></li>
            <li><a href="">Creative</a></li>
            <li><a href="">eCommerce</a></li>
            </li>
        </ul>
    </li>
</ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.