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.
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.
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.
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.
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.
Robert,
Show us some of your code so we have a starting point to work out a solution...
Cheers,
/Dirk
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 > 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 < $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 > 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 < $count">
<a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[local-name() = 'blogPost']/*[@isDoc][$itemindex +1]/@id)}">Next</a>
</xsl:if>
------------------------------------------------------------------------------------
Robert
DIrk,
I sent you my code a few days ago. Any thoughts on the original request. Thx much.
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.
Hi Robert,
How come they're in separate "Blog" trees? Does that mean that ALL posts have their own Blog ancestor?
/Chriztian
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
Still looking for a solution to this if anyone has ideas. Thank you.
is working on a reply...