Forum for discussing general topics related to Couch.
2 posts Page 1 of 1
Hi,

I have a list of projects that their order is sorted manually by the user trough arrows (k_up_down):

[project 1]
[project 2]
[project 3]
… and so on.

So, my problem is, inside each project I need a "Next Project" link.
That means that inside [project 1], "Next Project" link should take me to [project 2], and so on.

How can I achieve this?
The code I'm using takes me from [project 1] to [project 2] but then it gets "stuck" on [project 2]:

Code: Select all
<cms:pages start_on=k_page_link orderby='weight' limit='1' offset='1'>
<div><a href="<cms:show k_page_link />">next project</a></div>
</cms:pages>


Thanks!
Hi,

We can tweak the solution described in the following thread to work with manually ordered pages -
viewtopic.php?f=8&t=7087#p9409

To save you a few minutes, here is the adapted version -
Code: Select all
<cms:if k_is_page >
   <cms:php>
       global $CTX;
       $page_ids = explode( ",", "<cms:pages orderby='weight' order='asc' folder=k_page_foldername ids_only='1' />" );
       $cur_page_id = "<cms:show k_page_id />";
       $pos = array_search( $cur_page_id, $page_ids );
       if( $pos!==FALSE ){
          if( $pos>0 ){
             // Prev page id
             $prev_page_id = $page_ids[$pos-1];
             $CTX->set( 'prev_page_id', $prev_page_id, 'global' );
          }
          if( $pos<count($page_ids)-1 ){
             // Next page id
             $next_page_id = $page_ids[$pos+1];
             $CTX->set( 'next_page_id', $next_page_id, 'global' );
          }
       }
    </cms:php>

    <cms:if prev_page_id >
       <cms:pages id=prev_page_id skip_custom_fields='1'>
          <a href="<cms:show k_page_link />">Prev (<cms:show k_page_title />)</a>
       </cms:pages>
    </cms:if>
    <cms:if next_page_id >
       <cms:pages id=next_page_id skip_custom_fields='1'>
          &nbsp;<a href="<cms:show k_page_link />">Next (<cms:show k_page_title />)</a>
       </cms:pages>
    </cms:if>
</cms:if>

Hope it helps.
2 posts Page 1 of 1
cron