Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Jan 29, 2010 @ 15:38
    Dan
    0

    Get level 2 pages within particular parents

    Hi,

    I have a site like this:

    Home
    - News
    -- News item 1
    -- News item 2
    - Work
    -- Work item 1
    -- Work item 2
    - Play
    -- Play item 1
    -- Play item 2
    - Contact
    - Other

    I'm trying to create a macro to pull all level 2 items onto the homepage (i.e. a list containing: News item 1, news item 2, work item 1, work item 2, play item 1 and play item 2) ordered by a datepicker field common to all of the level 2 pages.

    I thought I could use umbraco.library:GetXmlNodeById($source) but I'm not sure how to add multiple sources.  I then thought I could try listing all level2 pages and filtering by the ids of the appropriate level1 pages, but when I do the following, nothing is returned:

    <xsl:variable name="level" select="2"/>
    <xsl:template match="/">
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    I thought this would return all level 2 pages, but it appears not.

    Could anyone point me in the right direction?

    Thanks all...

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 29, 2010 @ 16:02
    Thomas Höhler
    0

    Not really.. try this:

    <xsl:template match="/">
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node/node">
           
    <li>
                   
    <a href="{umbraco.library:NiceUrl(@id)}">
                           
    <xsl:value-of select="@nodeName"/>
                   
    </a>
           
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    for explanation: with the ancestor selector to level 1 you are selecting the home node. So you can be sure to get the top node from everywhere you are in hte hierachy. After that you are selecting all subnodes of the subnodes fromt he home node => the level 2 nodes You can also do the for-each via

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/descendant-or-self::node [@level=3]">

    hth, Thomas

  • Dan 1288 posts 3921 karma points c-trib
    Jan 29, 2010 @ 16:15
    Dan
    0

    Thanks Thomas, I've modified my code to the following:

    <xsl:template match="/">
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [(@id = 1050) or (@id = 1051) or (@id = 1052)]/node">
    <xsl:sort select="articleDate" order="descending"/>
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    This works, apart from it doesn't order the articles correctly - it's showing all the news ones first, then the work ones etc, even though they should be mixed up.  Is it possible to order them so that they're mixed together then ordered?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 29, 2010 @ 16:21
    Thomas Höhler
    0

    if they have all the attribute articleDate you can do this via

    <xsl:sort select="data [@alias='articleDate']" order="descending"/>

    hth, Thomas

     

  • Dan 1288 posts 3921 karma points c-trib
    Jan 29, 2010 @ 16:29
    Dan
    0

    Ah-ha!  So nearly there yet so far...

    Thank again Thomas.

Please Sign in or register to post replies

Write your reply to:

Draft