Using wp_list_categories like the the_category (showing just current categories of a post)

fromi’m using wp_list_categories to get an unordered list with headlines (on single.php inside the post-loop):

<ul><?php wp_list_categories('title_li=0');?></ul>

the thing is: i want to use it in the same way as “the_category” which means that i want to display ONLY the current categories of the post!

Read More

by now, it dsiplays ALL the categories and subcategories from the system (like it does using it in the sidebar and which makes sense there).

is there a way to do it?
thanks,
Jochen

EDIT: actual output (category list with ALL categories from the whole system:

<ul>    <li class="cat-item cat-item-10"><a href="#">Cat1</a>
<ul class='children'>
<li class="cat-item cat-item-18"><a href="#">Subcat1</a>
</li>
<li class="cat-item cat-item-13"><a href="#">Subcat2</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-1 current-cat"><a href="#">Cat2</a>
<ul class='children'>
<li class="cat-item cat-item-12"><a href="#">Subcat1</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-9"><a href="#">Cat3</a>
<ul class='children'>
<li class="cat-item cat-item-20"><a href="#">Subcat1</a>
</li>
<li class="cat-item cat-item-19"><a href="#">Subcat2</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-11"><a href="#">Cat4</a>
<ul class='children'>
<li class="cat-item cat-item-15"><a href="#">Subcat1</a>
</li>
<li class="cat-item cat-item-14"><a href="#">Subcat2</a>
</li>
</ul>
</li>
</ul>

this is good so far! but the expected output i want to get is the same list as above but with just the CATEGORIES FROM THE DISPLAYED POST (not every category form the system)… i think “current” was the wrong word (sorry, i’m not a native speaker)!!

for example i open a post (single.php) with the attached category “Cat1” i want to have an output like this:

<ul>    <li class="cat-item cat-item-10"><a href="#">Cat1</a>
<ul class='children'>
<li class="cat-item cat-item-18"><a href="#">Subcat1</a>
</li>
<li class="cat-item cat-item-13"><a href="#">Subcat2</a>
</li>
</ul>
</ul>

i hope you can help! thanks…

Related posts

Leave a Reply

1 comment