Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Graham Carr 277 posts 389 karma points
    Sep 21, 2012 @ 09:36
    Graham Carr
    0

    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?

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 23:47
    Chriztian Steinmeier
    0

    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.:

    <a href="?cat={@urlName}"><xsl:value-of select="@nodeName" /></a>

    * 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 :-) 

    /Chriztian 

  • Graham Carr 277 posts 389 karma points
    Sep 27, 2012 @ 13:42
    Graham Carr
    0

    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

  • Graham Carr 277 posts 389 karma points
    Oct 31, 2012 @ 18:06
    Graham Carr
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft