Ok, so the site im working on, has a "mega menu" as the top navigation. There are several sub section, and when you mouse over a section, the mega menu drops down and shows the content.
One of the features is showing a random article from that section. It works, but the only problem is sometimes it also shows just a sub-sub-section which it shouldnt.
Example of the structure:
Home -Section 1 --sub-section 1a ---article ---article --sub-section 1b ---sub-sub-section 1b ----article ----article -Section 2 the same
So the mega menu dropdown for say, Section 1, the random article picker should link ONLY to articles and ignore linking to sub sections.
add one for the level in the site structure, which is @level, probably 4 so [@level < 4], so you do not list items within the sub-section. Check the umbraco.config file for the level of items in the sub-section.
I already navigate a level or two down, but the articles are spread over two different levels. Here is the most correct navigation tree i can re-create:
So you only get the articles, or do as Euan suggested to only get items of the document type (which is the way I would recommend) if you have a specific document type for your articles.
As crazy as it seams, the articles consists of around 10 or so different document types. Yeah, its crazy, and its even crazier they are on different levels and what not. Either way, thats why i thought it would be easier the other way around. I tried excluding hte document types that the sections consist of, but it turned out the articles inherited from them so they were ALL excluded. Sigh... I will try your solutions tomorrow when i get back to my workplace again.
(Article and Section are of course DocumentType Aliases, so substitute your own actual names...)
EDIT: Just saw your previous reply, so I can see it's a bit more involved... ok, we'll just need to find something (a property maybe?) that's unique to all your "Article" types
Now thats a clever trick! Thank you for pointing that out. Its so simple yet i would never in a million years think about it.
Ive tested it several times and it looks like it ignores linking to the sections and now just the articles. Very clever indeed. Thank you for your time.
Excluding parents when picking random nodes
Ok, so the site im working on, has a "mega menu" as the top navigation. There are several sub section, and when you mouse over a section, the mega menu drops down and shows the content.
One of the features is showing a random article from that section. It works, but the only problem is sometimes it also shows just a sub-sub-section which it shouldnt.
Example of the structure:
Home
-Section 1
--sub-section 1a
---article
---article
--sub-section 1b
---sub-sub-section 1b
----article
----article
-Section 2
the same
So the mega menu dropdown for say, Section 1, the random article picker should link ONLY to articles and ignore linking to sub sections.
Here is my code so far:
I hope my description is sufficient.
Frederick,
Where you have the restriction of
[not(umbracoNaviHide = 1)]
add one for the level in the site structure, which is @level, probably 4 so [@level < 4], so you do not list items within the sub-section. Check the umbraco.config file for the level of items in the sub-section.
Richard
I already navigate a level or two down, but the articles are spread over two different levels. Here is the most correct navigation tree i can re-create:
Main (lvl 1)
-Section 1 (lvl 2)
--Sub-Section 1a (lvl 3)
---Sub-sub-section 1aa (lvl 4)
-----Article (lvl 5)
-----many more articles
---Sub-sub-section 1ab (lvl 4)
-----Articles (lvl 5)
--Sub-Section 1b (lvl 3)
---Article (lvl 4)
---More articles (lvl 4)
This is how i tried to get around the problem:
Hope it makes sense. My code picks a random article from section 1, but it also picks a section itself sometimes.
Are the articles/sections/subsections different doc types? If so, you should be able to use name()='doctypename'. something like:
Frederick,
I was thinking that you could do
So you only get the articles, or do as Euan suggested to only get items of the document type (which is the way I would recommend) if you have a specific document type for your articles.
Richard
As crazy as it seams, the articles consists of around 10 or so different document types. Yeah, its crazy, and its even crazier they are on different levels and what not. Either way, thats why i thought it would be easier the other way around. I tried excluding hte document types that the sections consist of, but it turned out the articles inherited from them so they were ALL excluded. Sigh... I will try your solutions tomorrow when i get back to my workplace again.
Hi Frederik,
If I understand you correct, you only want to pick a random node of type "Article", right? - So that's exactly what you should ask for with the XPath:
- include as much as you know, e.g. if they're really at any level below the first Section type (or whatever it's called):
(Article and Section are of course DocumentType Aliases, so substitute your own actual names...)
EDIT: Just saw your previous reply, so I can see it's a bit more involved... ok, we'll just need to find something (a property maybe?) that's unique to all your "Article" types
/Chriztian
- to follow up on that - could the articleHeading property maybe be what you need?
If so, you could select all descendants that has that property:
/Chriztian
Now thats a clever trick! Thank you for pointing that out. Its so simple yet i would never in a million years think about it.
Ive tested it several times and it looks like it ignores linking to the sections and now just the articles. Very clever indeed. Thank you for your time.
is working on a reply...