Required tag functions in 2.3 missing (27 posts)

  1. mhdhallak
    Posted 8 years ago #

    I was sort of expecting WP 2.3 would include helper functions and conditional tags for the new tagging system. Things like is_tag() to determine whether the current page is a tag archive. Also a function like get_the_tag or something like that for getting the tag in question.

    The reason I'm asking about this is that I'd like to design the tag loop page to show a title of "Tag archive for ..".

    Are those functions planned for another WP iteration?

  2. Jeremy Clark
    Posted 8 years ago #

    If you want to display a simple tag archive have a look at this.

  3. konstantinos
    Posted 8 years ago #

    Do the instructions Jeremy linked to work?

    I created a file named tag.php, upload to my theme's folder and proceeded to create a blank Page using the "Tag Archive" template. I've also updated my permalinks just in case.

    My .../tag/.. links now result in blank pages.

    I've tried various combinations and I'm still stuck. (How are you supposed to title the newly-created "Page"?)

    Any help would be appreciated -- thanks!

  4. Jeremy Clark
    Posted 8 years ago #

    Name the page something like Tag Archive. I've edited the instructions to reflect this. Review your single.php for the actual structure of the page, the template provided is only a rough framework. You'll need to edit it to fit your theme.

  5. mhdhallak
    Posted 8 years ago #

    The instructions provided by jeremyclark13 worked. I created an empty tag.php template file and a wrote a WP page that was based on this template, then I simply copied my index.php contents over to the tag.php and it worked fine.

    Now on to customizing the output in tag.php a little bit. I need a function to retrieve the tag being browsed. I'd like to be able to get things like $tag->tag_ID or get_tag_link(), much like the case with categories.

    Are there such built-in functions or are we looking at a possible plugin here?

  6. konstantinos
    Posted 8 years ago #

    Thank you for the quick reply -- it still doesn't work though.

    I have created a more advanced template, but to eliminate the possibility of any errors from my side I'm using yours.

    I save it as tag.php, upload it to the theme's directory, create a new page titled "Tag Archive", publish it, update the permalink structure (just in case), and it still doesn't work.

    Am I doing something wrong here? Thanks.

  7. Don't make a new Page. Just like you can have category.php and category-42.php for category archive pages, you can have tag.php and tag-sometag.php for tag archive pages (where "sometag" is the tag's slug).

    What I mean is that you don't need to specially create a Page and/or Page Template for these, they're built into the template hierarchy.

    Also, there is a new is_tag() function. So you can use that as well. It will return true on Tag Archive pages. is_tag() can also take the tag slug as a parameter, so you could do is_tag('sometag') to determine if this is the "sometag" tag archive page.

    @mhdhallak: There does need to be some kind of shortcut to get the tag info, but for the moment, try using get_query_var('tag') to get the current tag on tag archive pages.

  8. Jeremy Clark
    Posted 8 years ago #

    The reason I created the tag archive template is to have a specific page that all tags were displayed as well as customizing the way it looks when clicking on the tags, specifically always displaying a tag cloud. Also by creating a page it very easily adds it to the navigation of most blogs.

  9. mhdhallak
    Posted 8 years ago #


    Thanks I didn't know about the is_tag function. Is there a function to retrieve the tag in question (i.e., tag name, link, rss link)?

    Brent Loertscher created a plugin called Tag Functions which provides functions for tags similar to categories. That's what I was asking about. It seems those are not built in, otherwise he wouldn've gone through the trouble of creating this plugin.

  10. @jeremyclark13: True, and your method will work fine. Just saying that you don't need a custom Page Template and associated Page just to change the way the Tag Archive pages look.

    @mhdhallak: Looks like we're crossposting. Try get_query_var('tag').

    It's true that there are some gaps in the tag support though. Those gaps will eventually be filled in, this is all new and such. :)

    However, some of the functions he implemented in that plugin are already filled in. Might look at these:
    function get_tag_feed_link($tag_id, $feed = 'rss2')
    function get_tag_link( $tag_id )

  11. Jeremy Clark
    Posted 8 years ago #

    @otto I was looking at the template heiarchy and it shows that tag.php is right under tag-sometag.php. I don't think many themes include the tag.php template yet, would this be suitable instructions on how to create a new tag.php template. I wrote this part and I don't want to confuse anybody, if this isn't the correct way of doing it.

  12. @jeremyclark13: Yeah, I just added that to the Template Hierarchy when I noticed that it had not been documented yet.

    I would be careful about making a tag.php file as a Page Template. Not because it won't work, it will, but tag.php is used for Tag Archives as well. So people might be surprised when clicking on any tag takes them to that Page with the cloud and such.

    Tag Archives are generally what you get when you click on tags in posts, much like Category Archives are what you get when you click on a category name in a post.

    If you want to make a separate Page to show tag clouds, you might want to name it tagpage.php or something. Then it will only be a Page Template, and not also become the Tag Archive template.

  13. mhdhallak
    Posted 8 years ago #


    Thanks for the tip about get_query_var. Using this function I could easily get the tag information I was looking for:

    Tag ID:
    No clue yet

    Tag Name:
    $tag = get_query_var('tag');

    Tag Link:

    Tag RSS Feed:

  14. Eli Foner
    Posted 8 years ago #

    This code doesn't display the current tag on a tag page (/tag/xxx) - any ideas?

    <h2 class="entry-title">Tag: <?php get_query_var('tag'); ?></h2>

  15. @mhdhallak:

    Okay, try it like this.

    $tag_slug = get_query_var('tag');
    $tag_object = get_tag($tag_slug);
    $tag_id = $tag_object->term_id;
    $tag_feed_link = get_tag_feed_link($tag_id);
    $tag_link = get_tag_link($tag_id);
  16. @ix4li:

    Try <?php echo get_query_var('tag'); ?> instead.

  17. konstantinos
    Posted 8 years ago #

    Yeah, Jeremy as it is, it's not very clear.

    Otto: is there a sample tag.php page we could have a look at? The themes that come with the default install don't provide one, which is suprising.

    (I must be doing something wrong cause I still get blank pages.)

  18. Eli Foner
    Posted 8 years ago #

    @Otto42: That works!

    How would I display only the posts tagged with one particular tag?

  19. Otto: is there a sample tag.php page we could have a look at? The themes that come with the default install don't provide one, which is suprising.

    Like I said, this stuff is new. :)

    However, the default theme for 2.3 does include special code for tags. It does it by using is_tag() in the archive.php template, which is admittedly not the best way to demonstrate things. I should split that up into separate bits to provide a better idea. Maybe it'll make it into the next version. :)

    Generally speaking, copy your theme's index.php file to tag.php. Add some text to it, like "This is a Tag Archive". Voila. You'll get that when you click on any tag.

    All template pages are basically the same. Put in a Loop, it'll display the associated posts for your tags/categories/archives/dates/whatever you're getting.

  20. Eli Foner
    Posted 8 years ago #

    On my home page (home.php), I'd like to display 3 lists of recent post, each with different tags. (i.e. left column = x recent posts tagged 'XXXX', mid = x recent tagged 'YYY', right = x recent tagged 'ZZZ'). How would I accomplish this?

  21. ix4li: It's basically the same way you'd do it with categories. A separate query for each set.

    query_posts($query_string . "&tag=XXXX");
    // Do a Loop
    query_posts($query_string . "&tag=YYYY");
    // Do a Loop
    query_posts($query_string . "&tag=ZZZZ");
    // Do a Loop

    Around each Loop, you'd put your divs and such to make them go into columns or wherever else you want them on the page. And if you were displaying normal posts afterwards, you'd need to reset the query to normal with:

  22. konstantinos
    Posted 8 years ago #

    Otto42: thanks, it worked! (I was doing something wrong in my code.)

    BTW: along with, get_query_var('tag');, single_tag_title(); works as well, no?

    Thanks again for your help.

  23. Yeah, that would do it. I also noticed that get_query_var('tag_id') will get the tag_id too. See, it's new, not even I know all of them. :)

    So try these:
    Tag ID:
    $tag_id = get_query_var('tag_id');

    Tag Name:
    $tag_name = single_tag_title();

    Tag Link:
    $tag_link = get_tag_link(get_query_var('tag_id'));

    Tag RSS Feed:
    $tag_feed = get_tag_feed_link(get_query_var('tag_id'));

  24. Nick
    Posted 8 years ago #


    I've managed to create an tag archive. Now, I want to insert a link to the tag's feed into the left sidebar of the archive page.

    I've added the following code:

    div class="archive_feed">
     <a href="<?php get_tag_feed_link(get_query_var('tag_id')); ?>/feed">RSS feed for this tag</a>

    Unfortunately, the link does not work. When i click on it, I'm directed to the feed of my whole blog.

    What do I do wrong? Any ideas?

    I also want to count the posts that are filed under one tag. Suggestions?

    Any help is appreciated! THANKS!

  25. Try this instead:

    <div class="archive_feed">
     <a href="<?php echo get_tag_feed_link(get_query_var('tag_id')); ?>">
    RSS feed for this tag
  26. Nick
    Posted 8 years ago #

    Thank you, Otto42.

    Works fine now.

    Do you have any idea how i can count / display the number of posts filed under one tag?

  27. Kafkaesqui

    Posted 8 years ago #

    nick's last q about tag count covered here:


Topic Closed

This topic has been closed to new replies.

About this Topic