• Resolved anthonybarro

    (@anthonybarro)


    When using the wp_list_categories() variable (usage: https://codex.www.ads-software.com/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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter anthonybarro

    (@anthonybarro)

    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>';
      }
    ?>

    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.

    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 https://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>

    Mores,

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

    Thanks guys! Life save ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add <span> into wp_list_categories() variable?’ is closed to new replies.