So far I'm using the Content Picker to select the next page, but as I'm bound to have over a hundred pages this seems silly. Here's the code I'm using for this doomed idea:
<xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <!-- some output --> <!-- output link here, if there was a node picked: --> <xsl:apply-templates select="$currentPage/nextPageLink[normalize-space()]" /> <!-- some more output --> </xsl:template>
<!-- Template for link --> <xsl:template match="nextPageLink"> <a href="{umbraco.library:NiceUrl(.)}"><xsl:value-of select="@nodeName"/></a> </xsl:template>
</xsl:stylesheet>
Is there anyway I can have a "Next page" link appear on each page as it appears in the Content tree?
So a Parent (level 1) node would go to a child (2), then the child to a grand child (3). But the grand child could then go to the next page even if it's a (level 1).
You should be able to do this with $currentPage::following-node[1] ([1] being the first node in the set of following nodes). Have a look at this excellent axes vizualizer for a look at how that selects nodes.
You'll have to write some code to find the next page using the xpath axis. More info on this can be found on this wiki page. I guess you need to find out whether the current page has a child node and use that if it exists. If not, use the following sibling axis to find a node at the same level, and if that doesn't exist, use the following axis to get to the next page on a higher level.
Hmm... I can see that my whole answer didn't get saved in my last post. What I was trying to say was, that if your content is build the way i said before (home.aspx on level 1 and office.aspx on level 2), you can choose if the first level shall be vissible in the URLs or not.
Find this line in the web.config (around line 24):
If you change this value to false, then your top most node (the home-node in your solution) will be a part of the URL. As default the option is set to true.
Content --Site ----Home --------Office --------Retail --------Hotels --------Education --------Government ----About Us --------Our story ----Contact
When I tried to add your nextName code the name of the node on the front end displayed correctly but the link didn't work as it was missing the parent node in the link.
Hmm... That is pretty strange. I actually thought that you said the links where fine, but you just needed to write the correct link text. Besides that I think that you should stick with the true value in the umbracoHideTopLevelNodeFromPath key. I only wrote it because I thought you had another structure :)
If you've got the right id of the node where you are also getting the name from, I can't understand why the link won't work. Are the page vissible if you go to the generated link or do you get a 404? Or have you changed the URL of that page somehow (eg. through the umbracoUrlName, URL rewriting or something like that)? And one last thing, does the wrong link only fail on the office.aspx-node or is the generated link wrong on all of the nodes?
@Rich: The solution you provided would just use the name of the current page as the link text, and I don't think that is what we're trying to achieve - Or are we? :S
If you want to exclude nodes with a special document type I'm pretty sure you can just throw those nodes away by changing your variables to something like this:
Next page link?
I'm trying to create a "Next page" link.
So far I'm using the Content Picker to select the next page, but as I'm bound to have over a hundred pages this seems silly. Here's the code I'm using for this doomed idea:
Is there anyway I can have a "Next page" link appear on each page as it appears in the Content tree?
So a Parent (level 1) node would go to a child (2), then the child to a grand child (3). But the grand child could then go to the next page even if it's a (level 1).
You should be able to do this with $currentPage::following-node[1] ([1] being the first node in the set of following nodes). Have a look at this excellent axes vizualizer for a look at how that selects nodes.
JV,
You'll have to write some code to find the next page using the xpath axis. More info on this can be found on this wiki page. I guess you need to find out whether the current page has a child node and use that if it exists. If not, use the following sibling axis to find a node at the same level, and if that doesn't exist, use the following axis to get to the next page on a higher level.
Hope this helps.
Regards,
/Dirk
Thanks Sebastiaan and Dirk,
I've created this so far, but it's not displaying in the front end.
This is getting closer, but still not what I'm after.
It's not linking to pages on the same level.
Maybe you can find some help here
PrevNext Links
Almost there, just need the link to display correctly with the NiceUrl. Currently it's giving me the /home/office.aspx link text.
Anyone able to help me get this over the line?
Do you want to show the node name of the next node instead of the URL? If so, with your current code, you could create a new variable like this:
And then use this variable as the link text by replacing this:
With this:
Was that what you wanted to achieve?
/Kim A
Hi Kim,
I tried your suggestion. The name of the next node is displayed, but the link is incorrect.
Instead of linking to www.website/home/office.aspx, it's linking to www.website/office.aspx
How does your structure look in the content section? I'm guessing that your /home.aspx is on level 1 and the office.aspx is on level 2.
/Kim A
Hmm... I can see that my whole answer didn't get saved in my last post. What I was trying to say was, that if your content is build the way i said before (home.aspx on level 1 and office.aspx on level 2), you can choose if the first level shall be vissible in the URLs or not.
Find this line in the web.config (around line 24):
If you change this value to false, then your top most node (the home-node in your solution) will be a part of the URL. As default the option is set to true.
/Kim A
Hi Kim,
My content structure looks like this:
Content
--Site
----Home
--------Office
--------Retail
--------Hotels
--------Education
--------Government
----About Us
--------Our story
----Contact
When I tried to add your nextName code the name of the node on the front end displayed correctly but the link didn't work as it was missing the parent node in the link.
I tried it again changing the following:
<add key="umbracoHideTopLevelNodeFromPath" value="false" />
But this didn't help either, instead of linking to www.website/site/home/office.aspx, it's linking to www.website/site/office.aspx
Hmm... That is pretty strange. I actually thought that you said the links where fine, but you just needed to write the correct link text. Besides that I think that you should stick with the true value in the umbracoHideTopLevelNodeFromPath key. I only wrote it because I thought you had another structure :)
If you've got the right id of the node where you are also getting the name from, I can't understand why the link won't work. Are the page vissible if you go to the generated link or do you get a 404? Or have you changed the URL of that page somehow (eg. through the umbracoUrlName, URL rewriting or something like that)? And one last thing, does the wrong link only fail on the office.aspx-node or is the generated link wrong on all of the nodes?
/Kim A
Hi Kim,
The link works it's just the displayed name in the front end. Currenlty it's displaying like this:
Next page: /home/office.aspx
It should display like this:
Next page: Office
Hey JV,
That's because you are displaying the results of niceURL as your link and your href.
Change
to
Rich
Hmm... wasn't that what I told you how to acomplish in my answer right here?
To create a new variable called nextName like this:
and then change the code to this:
@Rich: The solution you provided would just use the name of the current page as the link text, and I don't think that is what we're trying to achieve - Or are we? :S
/Kim A
Hey Kim,
You're right, my bad for not reading the whole thread ;)
Rich
Thanks Kim,
You're original post was right! But I was replacing both "umbraco.library:NiceUrl($nextId)" with "$nextName". Which was my mistake.
Thanks for your persistance with this problem, and thanks to Rich Green for your efforts.
For those out there who want a link to the next page in their node structure, here's the final code:
Ahh great news JV!
I'm glad you got it working. Now I understand why there was suddenly a problem with the link instead of the link text :)
/Kim A
Thanks Kim,
I did just have a thought. I have some doctypes in my content tree that I don't want to show up in the "Next page" link.
I could use umbracoNaviHide on these items, however this hides the entire macro from the page.
Ideally I'm trying to find a way to hide certain doctypes and have the "Next page" skip to the next doctype.
e.g.
About Us
----Image node
Contact Us
The idea would be to hide "Image node" from the "Next page" link and the "About Us" "Next page" link display the "Contact Us" page.
Does that make sense?
If you want to exclude nodes with a special document type I'm pretty sure you can just throw those nodes away by changing your variables to something like this:
Haven't tested it though, but it makes sense in my head :)
/Kim A
Works like a cham!
Thanks again Kim, you're a legend!
Cheers,
JV
No problem JV. Just glad I'm able to help out :)
/Kim A
is working on a reply...