Forums

Display tags coming from a category (4 posts)

  1. Pierrick
    Member
    Posted 4 months ago #

    Hello All,

    I read this topic (http://wordpress.org/support/topic/get-tags-specific-to-category) about to get the tags specific to a category.

    I am almost there but cannot figure out how to dynamically get the category ID when you are on the page as opposed to have to specify the category IDs when you call the function which actually means that you get all the tags from all the specified categories - I have italicized and bolded up in the snippet below where you have to specify the category IDs.

    <?php
    // Category tag function

    $args = array(
    'categories' => '5,13,14'
    );
    $tags = get_category_tags($args);
    $content .= "<div>";
    foreach ($tags as $tag) {
    $content .= "<span>tag_link\">$tag->tag_name</span>";
    }
    $content .= "</div>";
    echo $content;
    ?>

    Thank you for your help!
    P

  2. Pierrick
    Member
    Posted 3 months ago #

    Hello All,

    Can anyone shed some light on the issue above. I am stuck...
    CHeers

    P

  3. alchymyth
    The Sweeper
    Posted 3 months ago #

    how to dynamically get the category ID when you are on the page

    are you talking about the category archive page?

    if so, then the category id would be:

    get_query_var('cat')

    i.e. try:

    $args = array(
    'categories' => get_query_var('cat')
  4. Pierrick
    Member
    Posted 3 months ago #

    Thanks Alchymyth, it did the trick!

    But when I click on these tags within a category page, it would show me all posts with that tag as opposed to only the posts from that specific category... Do you know how to sort that out?

    Example here - http://www.relequalsatypical.co.uk/category/sam/

    Thanks again!
    P

Reply

You must log in to post.

About this Topic