At the middle of my footer on this site, you've probably seen the list of tags. These are dynamically loaded by the tags I put in each blog post. How'd I do that? Pretty simple, actually - using the new snippet called "tagLister".
First off, download tagLister from Package Management, or get it here. Then install it into MODx Revolution.
To get started with tagLister, you'll first need a Template Variable to pull tagging data from. I've already detailed this in a prior post, but for those of you first reading this, just go ahead and create a textfield TV and name it 'tags'. Then give it access to your blog post templates (or whatever other templates you want tagging on).
Then just place tagLister wherever you want the tag list to render. It has some different properties available to it to adjust the output (documented here), but for now let's just keep it at the default state. So, your call will look like so:
[[!tagLister? &limit=`10`]]
This will generate a list (limited to 10) of the most popular tags used on your site. You can sort alphanumerically, as well. Those tags will also have links to your home page with '?tag=tagName' appended. So, if you're using getResourcesTag or getArchives (from Archivist) on your home page, those snippets will parse the tag REQUEST variable and automatically filter your results. Yes, that means tag-based navigation. My getResourcesTag call on my home page resource looks like this:
[[!getResourcesTag? &tpl=`blogPost` &parents=`34,35` &limit=`5` &depth=`5` &includeContent=`1` &includeTVs=`1` &showHidden=`0` &hideContainers=`1` &elementClass=`modSnippet` &element=`getResources` &pageVarKey=`page` ]] [[!+page.nav:notempty=` <div class="paging"> <ul class="pageList"> [[!+page.nav]] </ul> </div> `]]
Say you wanted the tag links from tagLister to point somewhere else, like an archives page? Simple: just use the 'target' property:
[[!tagLister? &target=`123` &limit=`5`]]
Where 123 is the ID of the Resource to link to. (Note we also limited it to 5 tags here.) Simple as that - tag-based navigation for your site!


Comments (2)
skseo:
Sep 03, 2010 at 06:30 PM
First of all, thanks for your great work!
Two qusetions, how can i put the selected tag in the pagetitle? And why doesn´t it work if i tag the id of the page i ike to tag i.e tag = [[+id]]. The tag appears and link ist working, but nothing will be displayed
Pawel:
Mar 25, 2011 at 10:40 AM
It would be nice to have seo friendly urls with those tags - example /tags/taglister.html
Add a Comment