Forums

[resolved] How to add a taglist/cloud on a specific tag page? (2 posts)

  1. cogmios
    Member
    Posted 3 years ago #

    I want to display a list of tags / tagcloud on the specific TAG archive pages themselves.

    But the tag list should only list the tags that are used on the specific postings with that TAG without that tag itself...

    Actually I do not even want the cloud but just an array of the tags along with how many postings inside that specific tag archive carry that tag.

    So e.g. I get "LOST" as a tag and then the headermenu will show "video (3)", "links (5)", "reviews (2)", etc... because it automatically picks it out the tag labelling.

    Has someone some lines of code to drop?

  2. cogmios
    Member
    Posted 3 years ago #

    Ok, no reply, I came up with the following that actually works (in case anyone is looking for it):

    function get_related_tags($tagname) {
    		global $wpdb;
    		$sqlstring="select name from $wpdb->terms where term_id in (" .
       	"select term_id from $wpdb->term_taxonomy where taxonomy=\"post_tag\" and term_taxonomy_id in (" .
       	"select distinct term_taxonomy_id from $wpdb->term_relationships where object_id in (" .
       	"select object_id from $wpdb->term_relationships where term_taxonomy_id =" .
       	"(select term_taxonomy_id from $wpdb->term_taxonomy where term_id=" .
       	"(select term_id from $wpdb->terms where name=\"".$tagname."\")))))";
    		$tagidarray = $wpdb->get_col($sqlstring,0);
    		$returnRelatedTagDiv='';
    		foreach($tagidarray as $relatedtag) {
    			if ($relatedtag != $tagname) {
    	  			$returnRelatedTagDiv .= "<a href=\"/about/" . $relatedtag . "\">";
    	  			$returnRelatedTagDiv .= $relatedtag;
    	  			$returnRelatedTagDiv .= "</a> ";
    				$tagid = fetch_tag_id($relatedtag);
    				//$returnRelatedTagDiv .= fetch_tag_amount($tagid);
    				$returnRelatedTagDiv .= "";
    			}
    		}
    		return $returnRelatedTagDiv;
    	 }

    as documented on http://edward.de.leau.net/wordpress-retrieve-the-set-of-tags-used-with-another-tag-20081110.html

    This is actually a hefty query so I wonder if it can be done better.

    Another thing... what would happen if I click a tag. then I come to the tag page of the tag with ALL postings. However I would then like to come to the tag page archive of the tag but with only the postings of the tag that I clicked on before... does anyone understand?

    A sort of refining query on tags.

Topic Closed

This topic has been closed to new replies.

About this Topic