by
KK » Sun Feb 28, 2016 6:30 pm
That is the kind of explanation I was looking for, John
Thanks, I get the problem now.
As a solution, I suggest you don't make any changes at the menu level i.e. continue using your current code -
- Code: Select all
<cms:nested_pages masterpage='index.php' depth='1' >
<li><a href="<cms:show k_menu_link />"><cms:show k_menu_title /></a></li>
</cms:nested_pages>
So, for example, the 'News' item will actually lead the visitor to 'news' page.
Once on that page, however, we'll now figure out if the current page ('news' in our example) has any children.
If yes, we'll loop through its children and redirect to the first child found.
This way, the experience would be seamless - clicking on 'News' will show 'Upcoming Events' to the visitor.
Following is how we can do it.
Currently it is likely that your template has code for the page_view, probably something like this -
- Code: Select all
<cms:if k_is_page>
<h1><cms:show k_page_title /></h1>
..
..
..
</cms:if>
Amend it to add make it as follows -
- Code: Select all
<cms:if k_is_page>
<cms:nested_pages root=k_page_name depth='1'>
<cms:if k_total_children >
<cms:nested_pages childof=k_page_name >
<cms:redirect k_nestedpage_link />
</cms:nested_pages>
</cms:if>
</cms:nested_pages>
<h1><cms:show k_page_title /></h1>
..
..
..
</cms:if>
And now, for any nested page that has children, visiting it will redirect to its first child.
To explain to you how the code works, following is the same code but with some notes attached -
- Code: Select all
<cms:if k_is_page>
<!-- get more nesting info about the current page
(setting root to the current page's name and depth of 1 we get only one page and that is the current page)
-->
<cms:nested_pages root=k_page_name depth='1'>
<!-- if it has any children .. ->
<cms:if k_total_children >
<!-- get its children .. -->
<cms:nested_pages childof=k_page_name >
<!-- .. and redirect to the first child page -->
<cms:redirect k_nestedpage_link />
</cms:nested_pages>
</cms:if>
</cms:nested_pages>
<h1><cms:show k_page_title /></h1>
..
..
..
</cms:if>
Hope it helps.
Please let me know.