• James182

    (@james182)


    Hi, I was wondering if there is any short snippet of code that allows you to display the current category you are in but also displays a hyphen in the middle, like you find with the permalinks. So if i was in the category “Music News” I could echo out the word “music-news”. Any help would be greatly appreciated!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael

    (@alchymyth)

    to be used in category.php (or achive.php)

    <?php echo get_category(get_query_var('cat'))->slug; ?>

    Ganners

    (@ganners)

    $categories = get_the_category($post->ID);
    print $categories->category_nicename;

    Is that what you’re after?

    Thread Starter James182

    (@james182)

    @ganners Thanks for your reply but for some reason it is now showing anything, not even in the source.

    @alchymyth That snippet of code works great!, another quick question is, if i am on the homepage for example, it shows “home” or on the search page it displays “Search”, assuming be a if and else statement? (sorry i am learning as go along)

    esmi

    (@esmi)

    Thread Starter James182

    (@james182)

    thx for the link esmi, that was really helpfull

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying Category / Slug Name’ is closed to new replies.