• What I am trying to do is add a different class for the first and last links. You can see the markup for the structure of my navigation I want below:
    Code

    help is much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mikka23

    (@mikka23)

    I worked out a way I can do it using php. The only problem is I don’t know how to dynamically get the first and last ID number.

    My examply php (at pastie.org)

    hey,

    i had the same probleme, then i found a function in a thread, but it did not work, so i rewrote it and is works pretty well,

    i’m shure it could be imporved by comdining both regex into one, but still, it works pretty good

    function add_last_class($input) {
    	if( !empty($input) ) {
    
    		$pattern = '/<li class="/is';
    		$replacement = '<li class="first ';
    
    		$input = preg_replace($pattern, $replacement, $input);
    
    		$pattern = '/<li class="(?!.*<li class=")/is';
    		$replacement = '<li class="last ';
    
    		$input = preg_replace($pattern, $replacement, $input);
    
    		echo $input;
    	}
    }
    
    /* the echo=0 parma is important here */
    add_last_class(wp_list_categories('title_li=&echo=0'));

    hope it helps

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List_Categories – how to make first and last link have different class’ is closed to new replies.