Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hey, looking for a way to modify this code so the href links to the first subpage of the parent page in the menu structure.

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>


I tried replacing the href to be <cms:show k_nestedpage_link /> but that did not work, I am sure there is a trick I missed in the doc.
John, we'll need more info about the context where you wish to do this.
Is it that when one visits the 'parent' page, the link in the mentioned menu points to the first child of that parent?

Please explain the use-case in detail.
Would help if you could post a screenshot of your HTML design marking out the portion you are trying to code.

Thanks.
KK wrote: John, we'll need more info about the context where you wish to do this.
Is it that when one visits the 'parent' page, the link in the mentioned menu points to the first child of that parent?

Please explain the use-case in detail.
Would help if you could post a screenshot of your HTML design marking out the portion you are trying to code.

Thanks.


Hi KK,

Sure.

Home
About
- Mission Statement
- Philosophy
- Staff
News
- Upcoming Events
- Register Online
Contact Us


The goal was to put links at the bottom of my site but only naming the parents as I did not want to list the sub pages also. However the code I use loads the link for the first page, the parent not the first sub page of that parent. So at the bottom it would result in:

Home - About - News - etc...

So since there are no landing pages, if someone were to click on "news" the goal is to have Couch put the link to the Upcoming Events (or first page in the sort order) and load that page or link to that page.

Thanks KK
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.
Hi KK,

Just had a chance to try this as I was on another project.

It is not working unfortunately.

Here is the code:

Code: Select all
<div class="col-xs-12 col-md-9">
   <div class="about-wel">
      <cms:show content />
   </div>
   <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>
   <cms:if k_page_id="105" >
        ....
        </cms:if>
</div>


I have 4 cms:if k_page_id's to load content based on the page that I load. The menu calls the index.php as it's master page to make the menu, is that what this code is missing? I tried to add that, but it did not work still.

I am not sure how I feel about the pages "redirecting" every time. I was hoping that in that menu code, I can do a check and just grab the link for the first child of the parent and display that link. :(

Thanks!
5 posts Page 1 of 1