WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add <span> into wp_list_categories() variable? (5 posts)

  1. anthonybarro
    Member
    Posted 5 years ago #

    When using the wp_list_categories() variable (usage: http://codex.wordpress.org/Template_Tags/the_category) it displays the categories in your blog.

    I have, however, in the mean time stripped the "title", which by default is "Categories:", so that it now displays the following HTML:

    <ul>
        <li><a href="">Category 1</a></li>
        <li><a href="">Category 2</a></li>
        <li><a href="">Category 2</a></li>
    </ul>

    What I need now, is to figure out how to add "<span>" into the mix, IN the tag, so it becomes:

    <ul>
        <li><a href=""><span>Category 1</span></a></li>
        <li><a href=""><span>Category 2</span></a></li>
        <li><a href=""><span>Category 2</span></a></li>
    </ul>

    I cannot for the life of me figure out how to do this. All help will be GREATLY appreciated!
    Thanks in advance.

    /Anthony

  2. anthonybarro
    Member
    Posted 5 years ago #

    For anyone who has the same issue, I found a solution based on an other one:

    <?php
      $categories = get_categories();
      foreach ($categories as $cat) {
      echo '<li><a href="'.get_option('home').'/'.get_option('category_base').'/'.$cat->category_nicename.'/"><span>'.$cat->cat_name.'</span></a></li>';
      }
    ?>
  3. macwise
    Member
    Posted 5 years ago #

    Thanks, anthonybarro. I wish the team would make all of these WP template tag arguments so that they are the same across the board. For example, why this granularity is possible with the bookmarks tag, but not the links, or categories, I will never understand.

  4. mores
    Member
    Posted 5 years ago #

    Strangely, anthonybarro's solution did not work on my system. get_option('home') and the category base were not being embedded so all the links went nowhere.

    Since I couldn't figure out why this happened (using 2.7.1 after all), I did some more googling and found http://wphacks.com/sliding-doors-wordpress-navigation-css-technique :

    <ul id="nav">
    <li><a href="<?php echo get_option('home'); ?>/"><span>Home</span></a></li>
    <?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i’, ‘<li$1><a$2><span>$3</span></a>’, wp_list_categories(’echo=0&amp;orderby=name&amp;exlude=181&amp;title_li=&amp;depth=1′)); ?>
    </ul>
  5. litetheme
    Member
    Posted 4 years ago #

    Mores,

    Kinda weird. I got mine running using anthonynarro's solution. WP 2.8.6.

    Thanks guys! Life save ;)

Topic Closed

This topic has been closed to new replies.

About this Topic