WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. 11Mystics
    Member
    Posted 6 years ago #

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

    http://mysite.com/?tag=cows,horses

    OR

    http://mysite.com/?tag=cows+horses

    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
    Member
    Posted 6 years ago #

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

    <?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
    Member
    Posted 6 years ago #

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

  4. wp_guy
    Member
    Posted 6 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":

    <?php
    
    $multitag = "";
    $conjunction = "";
    
    if($wp_query->query_vars['tag_slug__and']){
    	$the_tags = $wp_query->query_vars['tag_slug__and'];
    	$conjunction = "and";
    }elseif($wp_query->query_vars['tag_slug__in']){
    	$the_tags = $wp_query->query_vars['tag_slug__in'];
    	$conjunction = "or";
    }
    
    for($i=0;$i<count($the_tags);$i++){
    	$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
    Member
    Posted 5 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