by
KK » Wed Jan 08, 2014 10:57 am
A picture is worth more than a thousand words indeed
Thanks. I get it now.
I see that you are trying to link the 'home-view' (and, although you have not made it explicit, the 'folder-view' also) to the first page of the appropriate folder.
While your solution is to explicitly figure out that page's link and output the link in the menus,
I would have approached this problem a little differently.
NOTE: I am assuming that the folder hierarchy is flat and that every page is within some folder.
Let us start with the page-view
- Code: Select all
<cms:if k_is_page>
<!-- Sub navigation by folders (level 1) -->
<ul>
<cms:folders depth='1' orderby='weight'>
<li><a href="<cms:show k_folder_link />" <cms:if k_page_foldername=k_folder_name>class="current"</cms:if>><cms:show k_folder_title /></a></li>
</cms:folders>
</ul>
<!-- contents of the page -->
<h1><cms:show k_page_title /></h1>
<p>page contents here</p>
<!-- Sub navigation by pages (level 2)-->
(Contents of '<cms:show k_page_foldertitle />' folder)
<ul>
<cms:set current_page=k_page_name />
<cms:pages folder=k_page_foldername>
<li><a href="<cms:show k_page_link />" <cms:if k_page_name=current_page>class="current"</cms:if>><cms:show k_page_title /></a></li>
</cms:pages>
</ul>
</cms:if>
You'll see that visiting any page will properly display the two sub-menus we have
- folders with the current folder highlighted and
- pages within the current folder with the current page highlighted.
That done, let us now handle the home-view (i.e. when the main menu is clicked).
I'll make the link in the main menu point directly to the template itself (i.e. home-view)
- Code: Select all
<li><a href='<cms:link 'research-projects.php' />' <cms:if k_template_name='research-projects.php'> class="current"</cms:if>>Research Projects</a></li>
Add the following code to the template -
- Code: Select all
<cms:if k_is_home>
<cms:folders depth='1' orderby='weight'>
<cms:pages folder=k_folder_name>
<cms:redirect k_page_link />
</cms:pages>
</cms:folders>
</cms:if>
The code is a standard loop through the folders and their pages. What we are doing is that as soon as the first page of the first folder is reached,
we redirect to that page.
So, effectively, it is the page-view code we saw above that executes for the home-view.
We can handle the folder-view similarly -
- Code: Select all
<cms:if k_is_folder>
<cms:pages folder=k_folder_name >
<cms:redirect k_page_link />
</cms:pages>
</cms:if>
As you can see, it is always the page-view that gets displayed when clicking a folder or the template link (and, of course, clicking a page link too).
The complete code is
- Code: Select all
<!-- top menu -->
<li><a href='<cms:link 'research-projects.php' />' <cms:if k_template_name='research-projects.php'> class="current"</cms:if>>Research Projects</a></li>
<!-- home view -->
<cms:if k_is_home>
<cms:folders depth='1' orderby='weight'>
<cms:pages folder=k_folder_name>
<cms:redirect k_page_link />
</cms:pages>
</cms:folders>
</cms:if>
<!-- folder view -->
<cms:if k_is_folder>
<cms:pages folder=k_folder_name >
<cms:redirect k_page_link />
</cms:pages>
</cms:if>
<!-- page view -->
<cms:if k_is_page>
<!-- Sub navigation by folders (level 1) -->
<ul>
<cms:folders depth='1' orderby='weight'>
<li><a href="<cms:show k_folder_link />" <cms:if k_page_foldername=k_folder_name>class="current"</cms:if>><cms:show k_folder_title /></a></li>
</cms:folders>
</ul>
<!-- contents of the page -->
<h1><cms:show k_page_title /></h1>
<p>page contents here</p>
<!-- Sub navigation by pages (level 2)-->
(Contents of '<cms:show k_page_foldertitle />' folder)
<ul>
<cms:set current_page=k_page_name />
<cms:pages folder=k_page_foldername>
<li><a href="<cms:show k_page_link />" <cms:if k_page_name=current_page>class="current"</cms:if>><cms:show k_page_title /></a></li>
</cms:pages>
</ul>
</cms:if>
Does this help?
Please let us know.
Thanks.