How can I get wp_title() to display both tag names when a multi-tag query ran? (5 posts)

  1. 11Mystics
    Posted 7 years ago #

    I'm using the multiple tag link/query on my site:




    But any time you use that kind of query, the wp_title() tag will only show the first tag specified in your link, in this case "cows". The fact that "horses" was also specified in the link is totally unrecognized by wp_title()

    Is there a way to get wp_title() to display every tag that's specified? Or is there some other template tag that will do this?

  2. Avon
    Posted 7 years ago #

    You may want to use the plug-in wp_list_posts. It's for listing posts and does support multi-tags.

    <?php wp_list_posts(’display=tag&tag=tag1,tag2,tag3&show_date=true’); ?>

    Replace "tag1,tag2,tag3" with your own tags.

    Here is its author's site, but it's in Chinese.
    You may want to download it from here. I did a little translation.

  3. spider110
    Posted 7 years ago #

    it's very cool;
    if you understand ,i can help U

  4. wp_guy
    Posted 7 years ago #

    @Avon: WordPress 2.5 seems to have this feature already, no need for extra plugins.

    I came up with some *ugly* code that will set a variable containing the list of specified tags... like "cows, horses and pigs" or "cows, horses or pigs":

    $multitag = "";
    $conjunction = "";
    	$the_tags = $wp_query->query_vars['tag_slug__and'];
    	$conjunction = "and";
    	$the_tags = $wp_query->query_vars['tag_slug__in'];
    	$conjunction = "or";
    	$multitag .= $the_tags[$i];
    	if($i < count($the_tags)-2){
    		$multitag .= ", ";
    	}elseif($i == count($the_tags)-2){
    		$multitag .= " $conjunction ";

    You can put this somewhere in your tag.php or archive.php (before the title) and then output the title with:

    <?php echo $multitag; ?>

    I know... my solution is a little bit messy and complicated... but I haven't found any other solution.

  5. Covi
    Posted 6 years ago #

    OMG... so long time on it... and I just know about $wp_query->query_vars posibilities... sniff :(

    Thx! wp_guy ;)

Topic Closed

This topic has been closed to new replies.

About this Topic