Forums

Display category slug in template (not category the name) (2 posts)

  1. ThreeVisual
    Member
    Posted 3 years ago #

    Just a quick question... is there a way to display the category slug in a template (not the name of the category)?

    For example if I had a category called 'Post Category' is like to display the category as a slug so I can apply a style for it, so I'd like it to be displayed as post-category.

    I'd then use CSS so I can apply a style like this...

    <span class="post-category">

    Not sure if this really makes sense?

  2. stvwlf
    Member
    Posted 3 years ago #

    This function returns the cat slug for the cat ID passed into it

    ?php function get_cat_slug($cat_id) {
    	$cat_id = (int) $cat_id;
    	$category = &get_category($cat_id);
    	return $category->slug;
    } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.