Napson Ko
Napson Ko

Reputation: 31

Displaying the categories and subcategories - wordpress

i have a lot of categories and subcategories in my site. I display them manually, i mean i wrote:

<ul>
<li>..menu..</li>
<li>..menu..</li>
</ul>

I'm sure there is a right way to do it. I'm sure there is an function for that. Can anybody tell me ?

Thanks

Upvotes: 0

Views: 120

Answers (3)

Mark Karavan
Mark Karavan

Reputation: 2684

In most php-based content management systems, this will be handled by getting the object containing the categories and a foreach() loop.

echo "<ul>";
foreach($menus as $menu) {
    echo "<li>" . $menu->link . "</li>";
}
echo "</ul>";

Every CMS will have its own objects, but the loop is pretty standard.

Upvotes: 0

Amal
Amal

Reputation: 76646

Yes, there is.

Use wp_list_categories():

An example:

<ul>
<?php wp_list_categories('orderby=name&show_count=1&exclude=10'); ?> 
</ul>

This function takes care of the formatting too. If you want the unformatted results, you can use get_categories() instead..

Upvotes: 1

Emma Lewis
Emma Lewis

Reputation: 402

Sure, you can use wp_list_categories()

http://codex.wordpress.org/Template_Tags/wp_list_categories

Upvotes: 0

Related Questions