Copied to clipboard

Flag this post as spam?

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


  • M4TTHEW 21 posts 61 karma points
    Aug 05, 2009 @ 20:40
    M4TTHEW
    0

    Display number of child pages?

    I would like to display the number of child pages on a parent page, i don't want any other data from them like page names or content or anything, i just want a macro to count the number of child pages and return a number on the parent page.

    i.e.:

    PAGE A "this page has three child pages"

    -page1

    -page2

    -page3

    PAGE B "this page has one child page"

    -page4

     

    Can anyone point me in a helpful direction?

    TIA!

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 20:49
    Peter Dijksterhuis
    1

    You could create a xslt-macro. Put something like this in the macro:

    <xsl:value-of select="count($currentPage/node)"/>

    HTH,

    Peter

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Aug 05, 2009 @ 20:52
    Sebastiaan Janssen
    100

    In XSLT you can do something like this:

     

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    This page has <xsl:value-of select="count(descendant::node)"/> chilpage(s)
    </xsl:for-each>
  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Aug 05, 2009 @ 21:07
    Sebastiaan Janssen
    0

    My solution actually lists all the subpages and their subpages, so if you have:

    Page C

    - page5
    - page6
    --page7
    --page8

    Then it will say there is 4 childpages.

    Not sure if you will need this, but it could come in handy!

     

  • M4TTHEW 21 posts 61 karma points
    Aug 06, 2009 @ 20:55
    M4TTHEW
    0

    Thanks to both of you! a few questions though:

    1) Peter: your example gives me three links to the three subpages, "link link link" not a number of how many pages there are "3". I used the "List subpages from a changeable source" macro as a template and replaced the line here: <xsl:value-of select="@nodeName"/> with your line of code.

    2) Sebastiaan: your example gives me an error- "The variable or parameter 'level' is either not defined or it is out of scope." i copy/pasted your code into a clean macro and replaced the <!-- start writing XSLT --> with your code.

    sorry for the hassle, i appreciate the help dudes!

  • M4TTHEW 21 posts 61 karma points
    Aug 06, 2009 @ 21:25
    M4TTHEW
    0

    Sebastian: i put this: <xsl:param name="level"/> in the macro and now it doesn't give an error, but it doesn't display anything :(

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Aug 06, 2009 @ 21:41
    Sebastiaan Janssen
    0

    Matthew, sorry mate, I forgot to give you this as well:

    <xsl:variable name="level" select="1"/>
  • M4TTHEW 21 posts 61 karma points
    Aug 06, 2009 @ 22:28
    M4TTHEW
    0

    Sebastian, thanks! :) here's what i ended up using:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/self::node [string(data [@alias='umbracoNaviHide']) != '1']">
            <a href="{umbraco.library:NiceUrl(@id)}">   
                    </a>
                    <xsl:value-of select="count(descendant::node)"/> sub-pages available
    </xsl:for-each>

    this way i can choose which page i want the number of child pages counted from. awesome!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies