Forums

Select current category slug (5 posts)

  1. olikid
    Member
    Posted 1 year ago #

    Hi There,

    I'm working on a custom theme that's using the TDO Tag fix plugin to allow for filtering posts based on category then tag.

    In the theme, I've created a custom category template that then links through to the appropriate tag filed under each category - for example

    Current Page URL:
    http://xxx.com/category/

    Link to tag filter:
    http://xxx.com/category/?tag=blah

    I need a way of being able to dynamically output the current category slug for use in linking through the tags.

    Something like <?php echo get_query_var('slug'); ?>

    Although obviously that doesn't work (<?php echo get_query_var('tag_id'); ?> does for the tag ID though though for example)

    I've spent a couple of hours looking for a solution to what I though was a pretty simple issue - maybe I've just overlooked something pretty simple.

    Thanks!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    <?php echo get_category(get_query_var('cat'))->slug; ?>
  3. olikid
    Member
    Posted 1 year ago #

    YOU sir, have saved me HOURS!

    Thank you so so much.

    It's not at all obvious how to find that. Literally spent hours looking.

    Thank you.

  4. johnmcelborough
    Member
    Posted 1 year ago #

    Hi alchymyth

    The code above really helped me so thanks very much

    Does anyone know what the equivalent code would be to achieve the same thing on a single post page i.e. get the category slug of the category which the current post is within?

    Thanks again

    john

  5. alchymyth
    The Sweeper
    Posted 1 year ago #

    <?php
    foreach( get_the_category($post->ID) as $cat ) { echo $cat->slug; }; ?>

    http://codex.wordpress.org/Function_Reference/get_the_category

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.