Copied to clipboard

Flag this post as spam?

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


  • Robert Valcourt 70 posts 103 karma points
    Jun 23, 2011 @ 11:50
    Robert Valcourt
    0

    Creating Next/Back links to navigate between nodes

    Ok, so we have a blog. Post nodes are categorized within date folders. I'm trying to create a script that will put Next and Back links on each post that will allow navigation between them. Here is a sample structure:

    Blog > 2011 > 3 > 14 > postname
    Blog > 2011 > 2 > 5 > postname

    Notice that the post pages are not in the same folder tree.

    I've done a great deal of searching on this. I found a post here:
    http://our.umbraco.org/forum/developers/xslt/7177-previous-page,-next-page
    and here:
    http://www.nibble.be/?p=44

    All of the examples are for the old XSLT schema and do not function in my 4.7 site which is NOT set to use legacy. I have tried to convert the various examples provided on that page with no success. I have also tried using the available online convertors, still no success.

    Ideally, this script would ... when you reach the last node, link back to the first and vice versa.

    Can anyone help me with this? Please and thank you.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 23, 2011 @ 13:17
    Dirk De Grave
    0

    Robert,

    Show us some of your code so we have a starting point to work out a solution...

     

    Cheers,

    /Dirk

  • Robert Valcourt 70 posts 103 karma points
    Jun 23, 2011 @ 14:35
    Robert Valcourt
    0

    Dirk,

    This is the code Nibble created for the old schema:

    ------------------------------------------------------------------------------------
    <xsl:template match="/">
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'blogPost']/node">
     
    <xsl:if test="$currentPage/@id = current()/@id">
     <xsl:call-template name="prevnext">
        <xsl:with-param name="count" select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'blogPost']/node)"/>
        <xsl:with-param name="itemindex" select="position()"/>
      </xsl:call-template>
    </xsl:if>
     
    </xsl:for-each>
     
    </xsl:template>
     
    <xsl:template name="prevnext" >
    <xsl:param name="count" />
    <xsl:param name="itemindex" />
     
    <xsl:if test="$itemindex &gt; 1">
      <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'blogPost']/node[$itemindex -1]/@id)}">Previous</a>
    </xsl:if>
     
    <xsl:if test="$itemindex &lt; $count">
      <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'blogPost']/node[$itemindex +1]/@id)}">Next</a>
    </xsl:if>
    ------------------------------------------------------------------------------------

    Assuming it did in fact work in the old schema, here is my attemp to modify it to the new one (without success):

    ------------------------------------------------------------------------------------
    <xsl:template match="/">
    <xsl:for-each select="$currentPage/ancestor-or-self::*[local-name() = 'blogPost']/*[@isDoc]">
     
    <xsl:if test="$currentPage/@id = current()/@id">
     <xsl:call-template name="prevnext">
        <xsl:with-param name="count" select="count($currentPage/ancestor-or-self::*[local-name() = 'blogPost']/*[@isDoc])"/>
        <xsl:with-param name="itemindex" select="position()"/>
      </xsl:call-template>
    </xsl:if>
     
    </xsl:for-each>
     
    </xsl:template>
     
    <xsl:template name="prevnext" >
    <xsl:param name="count" />
    <xsl:param name="itemindex" />
     
    <xsl:if test="$itemindex &gt; 1">
      <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[local-name() = 'blogPost']/*[@isDoc][$itemindex -1]/@id)}">Previous</a>
    </xsl:if>
     
    <xsl:if test="$itemindex &lt; $count">
      <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[local-name() = 'blogPost']/*[@isDoc][$itemindex +1]/@id)}">Next</a>
    </xsl:if>
    ------------------------------------------------------------------------------------

    Robert

  • Robert Valcourt 70 posts 103 karma points
    Jun 29, 2011 @ 07:08
    Robert Valcourt
    0

    DIrk,

    I sent you my code a few days ago. Any thoughts on the original request. Thx much.

  • Robert Valcourt 70 posts 103 karma points
    Jun 30, 2011 @ 11:50
    Robert Valcourt
    0

    I continue to try and modify the original code to work in the 4.7 schema without success. Any have any other means by which to acheive this functionality? Please and Thx.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 30, 2011 @ 21:57
    Chriztian Steinmeier
    0

    Hi Robert,

    How come they're in separate "Blog" trees? Does that mean that ALL posts have their own Blog ancestor?

    /Chriztian

  • Robert Valcourt 70 posts 103 karma points
    Jun 30, 2011 @ 22:50
    Robert Valcourt
    0

    All posts are stored in Date folders corresponding to a property field with the alias 'postDate'. When a post is initially created, Umbraco will create tree stucture based on the date its created and then populate the 'postDate' field with that date. If two posts are created on the same day, then the final DAY folder may have one or more posts in it. If a user modifies the 'postDate' field and publishes the node, Umbraco will delete the empty date folders (if its empty) and create new one based on the new date value. Typical tree structure is as follows:

    Blog > 2010 > 9 > 12 > postname
    Blog > 2011 > 3 > 14 > postname
    Blog > 2011 > 2 > 5 > postname
    Blog > 2011 > 2 > 5 > postname2

    The script would be run by each post page. It would traverse up the blog node tree to the root: 'blogHolder', then find the next post and previous post using the value of 'postDate' as a reference. OR the script could simply use Umbraco's sort order by building a variable matching all nodes with the alias 'blogPost', evalute its current position in that list, find the next and previous positions, and create navigatable links to them.

    /Robert

  • Robert Valcourt 70 posts 103 karma points
    Jul 19, 2011 @ 22:08
    Robert Valcourt
    0

    Still looking for a solution to this if anyone has ideas. Thank you.

Please Sign in or register to post replies

Write your reply to:

Draft