Implementing a Tags system
There are different ways of doing it, and it's actually built into Umbraco, but I wanted to implement it from scratch as a training exercise to learn Umbraco. It involves several steps, so it's nice to summarize the process to get an overview.
Creating screenshots is rather time consuming, so I'll skip it this time.
My approach (thanks to Kenny / Xeed for pointing me in the right direction) :
- Create a new datatype called Tags with the Checkbox list renderControl, and adding prevalues for each of the tags.
- In my Blog Post document type, add a Tags datatype instance
- Then check the tags that applies to each Blog Post instance in the content tree
- The xml output will for each blog post instance be on the form
<node attributes>
<!-- blog post instance -->
<data alias="bodyText" attributes>xhtml blob</data>
<data alias="tags" attributes>comma seperated list of the checked tags</data>
</node>
- For the list of blog posts, implement a filter which only displays the the blog posts which has the requested tag checked. This involves getting a querystring argument into XSLT, which I will store as a variable called filterBy, and using it when iterating through the list of blog posts.
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="filterBy" select="umbraco.library:RequestQueryString('tag')" />
<xsl:for-each select="$currentPage/node [contains(./data[@alias='tags'], $filterBy)]">
displaying the blog post here
</xsl:for-each>
</xsl:template>
- Then output the comma seperated list of tags as a list of links using the tag name as a filter:
<xsl:variable name="tags" select="umbraco.library:Split(./data [@alias = 'tags'], ',')" />
<xsl:for-each select="$tags/value">
<a href="/blog.aspx?tag={.}">
<xsl:value-of select="." />
</a>
</xsl:for-each>
Now that the tags are displayed for the blog, and filtering is implemented, it's time to make a listing of all the defined tags to ease navigation on the site.
First I did a simple listing of all the defined tags:
<xsl:for-each select="umbraco.library:GetPreValues(1099)//preValue">
<a style="white-space: nowrap;" href="/blog.aspx?tag={.}">
<xsl:value-of select="." />
</a>
</xsl:for-each>
It works, but doesn't give the same impression as using a
Tag cloud. Luckily,
Christoph Ertl has already made an Umbraco
package for this, so after downloading his
ZIP file, it can be installed into Umbraco by going into the Developer section -> Packages -> Install local package. The dll is copied and registered and a XSLT and a Macro is automatically created and integrated into Umbraco. His package then needs to be pointed to my tags. This involves changing his method calls in his TagCloud.xslt to :
<xsl:value-of select="TagCloud.Helper:RenderTags($currentPage/ancestor-or-self::node/descendant-or-self::node[@nodeTypeAlias = 'BlogPost' and string(data [@alias='umbracoNaviHide']) != '1'], 'tags', '<a class=tc{1} href="/blog.aspx?tag={0}">{0}</a> ', 6)" disable-output-escaping="yes"/>
Then it's just a matter of calling his Macro from my master template:
<umbraco:Macro Alias="TagCloud" runat="server"/>
and adding css styles for the generated links:
/* Tag cloud */
a.tc1 { font-size: 100%; font-weight: 200; }
a.tc2 { font-size: 110%; font-weight: 300; }
a.tc3 { font-size: 120%; font-weight: 500; }
a.tc4 { font-size: 130%; font-weight: 600; }
a.tc5 { font-size: 145%; font-weight: 800; }
a.tc6 { font-size: 160%; font-weight: 900; }
/* KEEPING default hover behaviour
a.tc1:hover, a.tc2:hover, a.tc3:hover, a.tc4:hover, a.tc5:hover, a.tc5:hover, a.tc6:hover { text-decoration:underline; }
*/
Congratulations on having 1 of the most sophisticated blogs Ive arrive across in some time! Its just incredible how a lot you can take away from a little something simply because of how visually beautiful it is. Youve put collectively a excellent weblog space –great graphics, videos, layout. This is absolutely a must-see blog!
HLAHvF , [url=http://frkdytalkrql.com/]frkdytalkrql[/url], [link=http://xgmuorrmkobw.com/]xgmuorrmkobw[/link], http://xffbzrvbygzd.com/
viagra =-DDD purchase prednisone 1523 ultram pvifas
cheap auto insurance 771 insurance auto >:PPP car insurance quotes %-D
flight discount =[[[ air tickets afzok
business insurance 6077 life insurance 5034 home insurance zhptd
business insurance estimates 8( cheap life insurance >:-]]] cheapest car insurance jzc
insurance auto auctions :-[[ ghi health insurance 988260 life insurance premium 493
Small Business Insurance Quotes :-))) car insurance online :-]]] insurance auto 3744
cheap auto insurance ttgd auto insurance amv home insurance %-D
health insurance quotes 82497 affordable term life insurance :D life insurance company >:-D
cheap auto insurance =-]]] auto insurance zgemlr auto insurance quotes 8D
buy intravenous tramadol bkmq buy propecia 5mg %OOO cheap accutane online 11318
buy 5 pills valtrex zrgxd acomplia :[[[
affordable life insurance xswq florida auto insurance 669
cheap car insurance dzebdd health insurance quotes =-(( life insurance zau
levitra coy nexium 21317 cheap generic cialis ojxa
health insurance 714936 life insurance quotes 8-[ home insurance 27604
viagra %-D viagra %[[
state auto insurance =-((( auto insurance quotes 470 free car insurance quotes 836257
compare levitra viagra 8-PP accutane kgepzn
infinity auto insurance 691334 new york health insurance %-O cheap car insurance 7837
hair loss propecia brzz discount cialis gxkf
ghi health insurance 8] viagra prices :-PP
new jersey car insurance 8-OOO home insurance %-OOO homeowners insurance florida 8-D
generic propecia >:( buy your medicine cheaper ultram viagra mzugi seroquel wahsp
SzN5Zp http://fb7Vrp92nNkdpv8r6cmBva.com
health insurance quotes mxqe life insurance dtoh online car insurance =PPP cheapest auto insurance 994
Hello! fgedbdb interesting fgedbdb site!
Very nice site! [url=http://yieapxo.com/qoqvqr/2.html]cheap cialis[/url]
Very nice site! cheap cialis http://yieapxo.com/qoqvqr/4.html
Very nice site!
need to buy valtrex >:-]] nexium drag 945598 cialis 68373
doxycycline yagtmw cheap auto insurance 505005
cheap car insurance %-[[[ a auto insurance slovj cheap auto insurance 8-) life insurance quote =-OO
health insurance zlemb home insurance in florida :D car insurence 8OO life insurance quotes 8-DDD
Hello!
Hello!
cheap auto insurance 85050 life insurance rates >:[[ auto insurance quotes 6077 cheap car insurance shyyhr
home insurance =DD viagra >:[ auto insurance quotes nqlovd
health insurance 09245 auto insurance quotes 171373 auto insurance dkysn
auto insurance rates weh cheap car insurance :P health insurance providers :-] business insurance 8-DDD
tramadol bcdk life insurance jucfa viagra kgbhn auto insurance 1056 car insurance rates 8PP
whole life insurance policies 391648 life insurance quotes >:(( viagra 101160
http://www.insurancegod.com/auto_insurance_quotes.htm - cheap auto insurance
http://www.insurancegod.com/auto_insurance_quotes.htm - cheap auto insurance
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!
Hello,
great post!