I have some pages which can be assigned to multiple
categories, and on the listing page I need to be able to select a category and
it then shows all pages assigned to that category. Obviously a normal folder
structure wouldn’t work for this, as a node can only exist under another node.
How would you go about doing this, and what kind of script/xslt would be best
used to filter the pages based on the selected category.
Here is an example of what I mean:
Categories
Cold Cathode
LED
Interior Design
Exterior Design
Consultation
Maintenance
So a page might be assigned to both Cold Cathode and
Interior Design, and when selecting either Cold Cathode or Interior design it
would appear in the list.
Has anyone got any ideas what type of XSLT/CSHTML would be best to use for this, or maybe another method entirerly?
I've done this in more than a couple of different ways, on various sites - but here's one way it could play out:
* Categories are simple documents somewhere in the content tree (in the example they are Category docs under a Categories doc that sits below the "Home" node)
* Pages that need to reference these have categories property as a Multi-Node Tree Picker datatype that enables selection of multiple categories (may also be the CheckBoxTree datatype) - be sure to save as XML (instead of CSV)
Then to grab all nodes tagged with a specific category, you do this:
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Select all available categories -->
<xsl:variable name="categoryRoot" select="$siteRoot/Categories/Category" />
<!-- Grab the category from the URL -->
<xsl:variable name="category" select="umbraco.library:RequestQueryString('cat')" />
<!-- Get the nodes tagged with $category -->
<xsl:var name="taggedNodes" select="$siteRoot//*[@isDoc][categories//nodeId = $categories[@urlName = $category]/@id]" />
<!-- Do stuff with them -->
<xsl:apply-templates select="$taggedNodes" />
.. OR ..
<xsl:for-each select="$taggedNodes"> ... </xsl:for-each>
Hope that starts enough to get you going - otherwise, come back :-)
Many thanks for the reply, I will have a go at implementing it. Another couple of questions though, if I wanted to have an "ALL" option on the category selector, how would you implement that, and would this work for a site which has different categories for a particular node type (e.g. I have categories for Products and categories for Projects)
In the category solution you posted, how did you handle URLRewriting?? I have tried a couple of methods but still can't get the urls to rewrite correctly, e.g.
Categorisation and listing of nodes
I have some pages which can be assigned to multiple categories, and on the listing page I need to be able to select a category and it then shows all pages assigned to that category. Obviously a normal folder structure wouldn’t work for this, as a node can only exist under another node. How would you go about doing this, and what kind of script/xslt would be best used to filter the pages based on the selected category.
Here is an example of what I mean:
Categories
Cold Cathode
LED
Interior Design
Exterior Design
Consultation
Maintenance
So a page might be assigned to both Cold Cathode and Interior Design, and when selecting either Cold Cathode or Interior design it would appear in the list.
Has anyone got any ideas what type of XSLT/CSHTML would be best to use for this, or maybe another method entirerly?
Hi Graham,
I've done this in more than a couple of different ways, on various sites - but here's one way it could play out:
* Categories are simple documents somewhere in the content tree (in the example they are Category docs under a Categories doc that sits below the "Home" node)
* Render the category selector as links, e.g.:
* Pages that need to reference these have categories property as a Multi-Node Tree Picker datatype that enables selection of multiple categories (may also be the CheckBoxTree datatype) - be sure to save as XML (instead of CSV)
Then to grab all nodes tagged with a specific category, you do this:
Hope that starts enough to get you going - otherwise, come back :-)
/Chriztian
Hi Chriztian,
Many thanks for the reply, I will have a go at implementing it. Another couple of questions though, if I wanted to have an "ALL" option on the category selector, how would you implement that, and would this work for a site which has different categories for a particular node type (e.g. I have categories for Products and categories for Projects)
Cheers,
Graham
Hi Chriztian,
In the category solution you posted, how did you handle URLRewriting?? I have tried a couple of methods but still can't get the urls to rewrite correctly, e.g.
/products/cold-cathode.aspx
to rewrite to
/products/product-list.aspx?cat=cold-cathode
Any help or ideas would be appreciated.
Graham
is working on a reply...