Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im currently using <?php wp_list_categories('child_of=4&title_li='); ?> to echo out a list of my categories. I'm wondering how I could append some html (specifically an » to the end of each LI within the link.

See this screenshot for an example of what I'm trying to do:

http://nikibrown.com/uploads/4662272c3f00c669b17952c10d21901c.png

share|improve this question

6 Answers 6

I think this is the cleanest and WordPressiest way to do it:

<?php
$menu_args = array(
    'child_of' => '4',
    'title_li' => '',
    'link_after' => '&raquo;',
);
wp_list_categories($menu_args);
?>
share|improve this answer
    
Thanks! This was the answer I was looking for, just wasn't googling the right things! –  nikibrown Feb 1 '11 at 15:53

Use the CSS :after pseudo-class.

I know people aren't big on psuedo-classes, but they work in all major browsers now. There's no reason not to use them.

share|improve this answer

Here is the method I would do using PHP str_replace:

<?php
$variable = wp_list_categories('child_of=4&echo=0&title_li=');
$variable = str_replace('</a>', ' »</a>', $variable);
echo $variable;
?>
share|improve this answer

It may make more sense to create the desired visual style using CSS alone. This keeps presentation separate from content generation.

li.cat-item { 
  background: url(../image/arrows.png) no-repeat;
}

You may already know this, as you are using the parameters already, but you would of course need to remove the “&title_li=” from the parameters to keep the CSS hooks.

share|improve this answer
    
Yeah I thought about that, to be honest i just was lazy and appended the &raquo; via jquery :) –  nikibrown Feb 1 '11 at 3:54

After much searching myselft, I found the answer to this here:

To summarise, the code to append a '>' to the end of each category is:

    <?php

    $taxonomy     = 'category taxonomy';
    $orderby      = 'name';
    $show_count   = 1;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    $empty        = 0;

    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title,
      'hide_empty'   => $empty
    );
    ?>

    <ul>
        <?php 
        $variable = wp_list_categories($args);
        $variable = str_replace('</a>', ' &gt;</a>', $variable);
        echo $variable; 
        ?>
    </ul>

Hope this helps. The key is the $empty parameter.

share|improve this answer

i would say either the css or use jquery to append. Say its in your div#sidebar, you could do something like

$('#sidebar ul li a').append('&lt;span style="color:#ff0000;"&gt;htmlmarkuphere&lt;/ span&gt;'); 

and itd at least be displayed in line and inside the anchor. or do append to the li to get it after the a but in the li.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.