WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_categories to display terms without hyperlinks (6 posts)

  1. Henry
    Member
    Posted 1 year ago #

    I am using wp_list_categories to display a list of top level terms and their subterms. All the terms are displayed as links.

    How could I use wp_list_categories to display terms without being hyperlinked?

  2. egado
    Member
    Posted 1 year ago #

    Hope this simple solution works for you...

    <ul>
      <?php
      foreach (get_categories() as $category){
        echo "<li>";
        echo $category->name;
        echo "</li>";
      } ?>
    </ul>
  3. Henry
    Member
    Posted 1 year ago #

    @egado

    Thanks for the suggestion, this works for displaying categories. The problem I have is I am trying to display terms from a custom taxonomy I have set up.

    The code I have is as follows

    <ul>
                  <?php wp_list_categories($post->ID, 'taxonomy=MYTAXONOMYNAME&hide_empty=1&title_li='); ?>
    
                  </ul>

    Using this on single.php this displays the taxonomy terms as hyperlinks. I'd like to display the taxonomy terms without hyperlinks.

  4. egado
    Member
    Posted 1 year ago #

  5. Henry
    Member
    Posted 1 year ago #

    I have used Scribu's tutorial to extend the category walker so do need to use wp_list_categories to display the terms as I want to maintain the "top-level" and "second-level" hierarchy.

  6. Henry
    Member
    Posted 1 year ago #

    Scribu doesn't seem to be available right now so I had to scrap using his tutorial for the time being. I ended up doing it like this:

    <ul>
        <?php $iterms = wp_get_post_terms($post->ID, "TAXONOMY"); ?>
        <?php foreach($iterms as $iterm) : ?>
    	<?php if($iterm->parent > 0) { ?>
    			 <li class="second-level-item"><?php echo $iterm->name; ?></li>
    			<?php } else { ?>
    			 <li class="top-level-item"><?php echo $iterm->name; ?></li>
    			<?php } ?>
    
        <?php endforeach; ?>
    </ul>

    @egado - thanks for your help

Topic Closed

This topic has been closed to new replies.

About this Topic