Copied to clipboard

Flag this post as spam?

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


  • Adam Betts 5 posts 25 karma points
    Oct 02, 2011 @ 23:25
    Adam Betts
    0

    Display the top 5 child nodes

    Hi Umbraco

    This is not a casual cry forhelp - I've been stuck for 3 weeks on this apparantly simple issue:

    On my homepage I want to list the last 5 child 'news items I have created, regardless of parentage - in date order (recent first)

     

    My structure is:

     

    Home

     - News

       *New item 1

       *New item 2

       *New item 3

    - Guff

     *Guff item 1

     *Guff Item 2

     

    etc

     

    I want to list all the sub items in reverse date order, most recent first, regardless of parentage.

     

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" indent="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:variable name="level" select="1"/>
    <xsl:template match="/">


    <xsl:for-each select="$currentPage/*">
    <xsl:for-each select="./child::*">
    <xsl:sort select="@createDate" order="descending"/>
    <xsl:if test="@level=3">
    <xsl:value-of select ="@nodeName"/>
    <br></br>
    <xsl:comment><xsl:value-of select ="content" disable-output-escaping="yes"/></xsl:comment>
    <br></br>
    </xsl:if>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>



     

     

    This is my best shot so far.  It lists the level 3 items, but only in date order per node, rather that date order full stop.  I.e my list could be:

     

    Guff item1

    News item 1

    News Item 2

    Guff Item 2

    etc,,,

    Surely somone has done ths before!!!!  I'm close to giving up.

     

    Adam

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 02, 2011 @ 23:33
    Chriztian Steinmeier
    0

    Hi Adam,

    This should be a good starting point - change the two NewsItem alliases to the alias of your News Document Type:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <!-- Number of items to show -->
        <xsl:variable name="maxItems" select="5" />
    
        <xsl:template match="/">
            <xsl:for-each select="$siteRoot//NewsItem">
                <xsl:sort select="@createDate" data-type="text" order="descending" />
                <xsl:if test="position() &lt;= $maxItems">
                    <xsl:apply-templates select="." />
                </xsl:if>
            </xsl:for-each>
        </xsl:template>
    
        <xsl:template match="NewsItem">
            <section class="news">
                <header>
                    <h1><xsl:value-of select="@nodeName" /></h1>
                </header>
    
                <xsl:value-of select="content" disable-output-escaping="yes" />
    
            </section>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 03, 2011 @ 00:27
    Fuji Kusaka
    0

    Sorry I just deleted my reply, havent refresh my page and didnt know Chriztian did reply.

     

  • Adam Betts 5 posts 25 karma points
    Oct 03, 2011 @ 23:28
    Adam Betts
    0

    Thanks for the reply Chriztian - that worked a treat with very little tweaking. 

Please Sign in or register to post replies

Write your reply to:

Draft