SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Category and Tags

    Hi there,

    Hoping some one can help me. I have 3 categories used as menus. They function giving the sense of three separate blogs on one parent blog. Is there a way when I search on a specific tag (which may be associated to multiple categories), to have the returned results separated by category? Or, if I'm in a certain category, to have, when clicking a tag, the results just show me the tag related to the specific category? Thanks very much.

  2. #2
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    205
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i think the simple way is using a function which will display a tags to related category of your choice... :

    function get_category_tags($args) {
    global $wpdb;
    $tags = $wpdb->get_results
    ("
    SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
    FROM
    wp_posts as p1
    LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
    LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
    LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,

    wp_posts as p2
    LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
    LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
    LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
    WHERE
    t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
    t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
    AND p1.ID = p2.ID
    ORDER by tag_name
    ");
    $count = 0;
    foreach ($tags as $tag) {
    $tags[$count]->tag_link = get_tag_link($tag->tag_id);
    $count++;
    }
    return $tags;
    }
    Then add this to your theme :

    $args = array('categories' => '10,11,12');
    $tags = get_category_tags($args);
    Change the 10-11-12 to your Categories ID !

    Goodluck

  3. #3
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, thanks so much for this. I hate to ask, but where would I put this function statement (sorry, I'm new to all this).


    Quote Originally Posted by deadmix View Post
    i think the simple way is using a function which will display a tags to related category of your choice... :



    Then add this to your theme :



    Change the 10-11-12 to your Categories ID !

    Goodluck

  4. #4
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    205
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jstabb View Post
    Wow, thanks so much for this. I hate to ask, but where would I put this function statement (sorry, I'm new to all this).
    hello, no problem we all have to ask when the things get Rough

    Check your theme and put the first code on functions.php and the second code put it in single.php

    Goodluck

  5. #5
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again, deadmix! Much appreciated.

    Quote Originally Posted by deadmix View Post
    hello, no problem we all have to ask when the things get Rough

    Check your theme and put the first code on functions.php and the second code put it in single.php

    Goodluck

  6. #6
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    205
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jstabb View Post
    Thanks again, deadmix! Much appreciated.
    You are welcome


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •