WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add a class on an li for "current category" (2 posts)

  1. Noel Forte
    Member
    Posted 1 year ago #

    Hi-
    Currently I'm using this code to display a string of breadcrumbs ( Link / Link / Link) across the top of my archive pages.

    <?php
    	$cat_arguments = array(
    	  'orderby' => 'name',
    	  'parent' => 0
    	  );
    	$cats = get_categories($cat_arguments);
    	$i = 0;
    	foreach($cats as $category) {
    		echo '<li><a href="'.get_category_link( $category->term_id ).'">'.$category->name.'</a>';
    		$i++;
    		if ($i < count($cats)) {
    			echo '<span class="divider">/</span></li>';
    		}
    	}
    	?>

    However, I want to add a class to the li that contains the name of the currently displaying category. What's the best way to do this?

  2. Noel Forte
    Member
    Posted 1 year ago #

    UPDATE: I was able to figure this out, thanks to some conditional tags.

Topic Closed

This topic has been closed to new replies.

About this Topic