Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello,

Searching the forum I found multiple solutions to use next & previous buttons to switch between nested pages.

viewtopic.php?f=4&t=7457&p=11014&hilit=next+prev+pages#p11014
viewtopic.php?f=8&t=7087&hilit=next+prev+pages

What I want to archieve is to have these buttons switch between the top-level pages only like Chapter 1 and Chapter 2 in the code below.

Code: Select all
Chapter 1
    Page 1
    Page 2
    Page 3
Chapter 2
    Page 3
    Page 4
    Page 5


How can I target only these nested_pages so switching between chapters would become possible?
Hi Gizmo,

I am sure we can code something up adapting the logic used in the examples you mentioned.

However, before we do that could you please detail a little more the use-case that you have?
Specifically, what do we show for the 'next' and 'prev' chapters as we visit the various pages e.g.-
a. on the 'home-view' of the template?
b. on 'Chapter1'
c. on 'Page1'
d. on 'Chapter2'
e. on 'Page3'

Thanks
Hello KK,

I'll explain my problem.
Back in December I posted viewtopic.php?f=4&t=7821

I managed to find a solution based on pages but without creating my own admin screen.
Everything worked on the frontend but in the backend I couldn't get sorting the pages to work like I wanted. In the end sorting based on date was the best I could get to work although sorting on folder would have been the best solution.

Lately I got back to your nested_pages solution. I rebuild the code so everything working like the pages version but now with ordering possible in the backend. Your solution worked like a charm (Thanks for helping me find the solution) but for the purpose I needed I had to rewrite a bit.

I came up with the following solution:

The index page shows the title and all the chapters that have subpages. Selecting a chapter jumps straight to the first page of this chapter. Using this in combination with a bit of jQuery code it became possible to browse the articles of a chapter just like paginate does with some visual goodies.

index.php

Code: Select all
<div class="content">
   <cms:show index_title />
   <div>
      <ul class="menu">
         <cms:nested_pages masterpage='chapters.php' depth='1' >
            <li><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
         </cms:nested_pages>
      </ul>
   </div>
</div>


chapters.php:

Code: Select all
<cms:if k_is_page>
    <cms:if k_nested_parent_id='-1'>
      <cms:nested_pages masterpage='chapters.php' include_custom_fields='1' childof=k_page_name >

         <div class="content">
               <h1><cms:show k_nestedpage_title /></h1>
               <cms:show content_nested />
         </div>

      </cms:nested_pages>
   <cms:else />
      <cms:nested_pages masterpage='chapters.php' include_custom_fields='1' root=k_page_name >

         <div class="content">
               <h1><cms:show k_nestedpage_title /></h1>
               <cms:show content_nested />
         </div>

      </cms:nested_pages>
    </cms:if>
</cms:if>
<cms:if k_is_list>
   <cms:nested_pages masterpage='chapters.php' include_custom_fields='1' childof=k_page_name >

      <div class="content">
            <h1><cms:show k_nestedpage_title /></h1>
            <cms:show content_nested />
      </div>

   </cms:nested_pages>
</cms:if>


A submenu.html snippet included in the chapters.php shows the the chapter menu and the articles belonging to a chapter.

Code: Select all
<!-- chapter menu -->
<cms:nested_pages masterpage='chapters.php' extended_info='1' depth='1' >
   <cms:if k_level_start >
      <cms:if k_level='0'>
          <ul class="chapterMenu">
      <cms:else />
          <ul>
      </cms:if>
   </cms:if>
   
   <cms:if k_element_start >
      <li id="item-<cms:show k_nestedpage_name />" class="level-<cms:show k_level/><cms:if k_total_children> has-submenu</cms:if><cms:if k_first_child> first</cms:if><cms:if k_last_child> last</cms:if><cms:if k_is_active> active</cms:if><cms:if k_is_current> current</cms:if>">
      <a href="<cms:show k_menu_link />"><cms:show k_menu_title /></a>
   </cms:if>
   
   <cms:if k_element_end ></li></cms:if>
   <cms:if k_level_end ></ul></cms:if>
</cms:nested_pages>

<!-- article based on article menu -->
<ul id="menu-toc" class="menu-toc">
   <cms:nested_pages masterpage='chapters.php' childof=k_page_name >
      <li><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
   </cms:nested_pages>
</ul>


This is a working solution. This shows all chapters in the chapter menu. But what I'm trying to achieve is a solution that shows only the previous and next chapter based on the current chapter selected.

To sum it all up:
- index.php shows only all the chapters, no submenu is shown;
- selecting a chapter on the index.php jumps straight to the first article of a chapter;
- chapters.php has a submenu with two menu's one for the chapters and one for the articles of a chapter.
- the Chapter1 and Chapter2 pages are only visible in listview which makes chapterMenu obsolete because all pages are shown in the menu-toc;

I hope my long post gives you a good idea how the website functions.
3 posts Page 1 of 1