List of Directory categories in my template


Trying to work out how to list the categories for my directory plugin within my sidebar.php page in my template.

I have this so far:
<?php if(get_post_type() == 'directory_listing') { ?>
<div class="menu-side">

    <?php some_fnc_here_to_get_categories(); ?>
<?php } else { blah... ?>

Any ideas?

  • Kimberly
    • Champion of Loops

    Hi Ali,

    Welcome to the WPMUDEV Community!

    You can try this:

    <?php $categories = get_categories("taxonomy=yourtaxonomy");
    foreach ($categories as $category) :
    echo '<li>' . $category->name . '</li>';

    Please let me know if you have any luck with this.



  • ali_wright
    • WPMU DEV Initiate

    Hi Kimberly,

    Thanks for this :slight_smile:

    Got it to work. At first I was only seeing the category I was in (as I've only got one listing in one of the categories set up so far), then realised I needed to set an extra parameter 'hide_empty':

    $listing_args = array('taxonomy'=>'listing_category','hide_empty'=>0);
    $categories = get_categories($listing_args);
    foreach ($categories as $category) :
       echo '<li><a href="../../listings-category/'.$category->slug.'/">' . $category->name . '</a></li>';

    Thanks again for your help!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.