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?
If you want to display a simple tag archive have a look at this.
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!
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.
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?
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.
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.
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.
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.
@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
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 )
@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.
@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.
Thanks for the tip about get_query_var. Using this function I could easily get the tag information I was looking for:
No clue yet
$tag = get_query_var(‘tag’);
Tag RSS Feed:
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>
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);
- The topic ‘Required tag functions in 2.3 missing’ is closed to new replies.