Reputation:
So i have this dilemma on displaying a list of all the parent categories in wordpress.
I'm using this code below:
<ul><li><?php wp_list_categories('orderby=order&title_li=&depth=1'); ?></li></ul>
Unfortunately, this doesn't work which I really don't know why. what happens is it only shows the only ONE category.
I would appreciate anyone's help on this please.
Upvotes: 2
Views: 3747
Reputation: 738
Try this one. I have tested before
<?php
$args = array(
'orderby' => 'name',
'hierarchical' => 1,
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => 0,
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a><br>';
}
?>
Or try this. Let me know which one is better.
<?php wp_list_cats('optionall=0&depth=1&list=0&exclude=1&children=0&hide_empty=0'); ?`>
Upvotes: 5