Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
How do I create next and previous buttons that will allow visitors on my website to move to the next or previous post after they are done reading the current one.
Hi!
Some time ago I needed a solution for this and KK was so kind to help me out with the following code:
Code: Select all
            <cms:php>
                  global $CTX;
                  $page_ids = explode( ",", "<cms:pages 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 />"><i class="fa fa-angle-left"></i> <cms:get_custom_field 'text_for_previous_article' masterpage='globals.php' /></a>
                  </cms:pages>
            </cms:if>
            <cms:if next_page_id >
              <cms:pages id=next_page_id skip_custom_fields='1'>
                  <a href="<cms:show k_page_link />"><cms:get_custom_field 'text_for_next_article' masterpage='globals.php' /> <i class="fa fa-angle-right"></i></a>
               </cms:pages>
            </cms:if>
I hope this code will work for you, too.
This is a preview of my Project/Blog list view and a single Project/Blog page view attache below:
All projects.JPG
All projects.JPG (71.92 KiB) Viewed 1808 times

Single page view.JPG
Single page view.JPG (74.45 KiB) Viewed 1808 times


How do i implement your solution in my code below:
Code view.jpg
Code view.jpg (453.56 KiB) Viewed 1808 times


Thank you
Never mind I have been able to implement it but I realized another problem. Anytime I click to the next post, my footer is repeated at the bottom of the page. What could be the solution ?
Never mind I have been able to implement it but I realized another problem. Anytime I click to the next post, my footer is repeated at the bottom of the page. What could be the solution ?
Repeated footer.JPG
Repeated footer.JPG (50.31 KiB) Viewed 1804 times


Lastly: What is the highlighted text meant to do as seen in the image below? Thank you
Text for next article.JPG
Text for next article.JPG (21.68 KiB) Viewed 1804 times
adimpressions wrote: Lastly: What is the highlighted text meant to do as seen in the image below? Thank you
Text for next article.JPG

The highlited text is the name of the editable in globals.php template from where you can change (from the admin panel) the text shown on the front-end for your visitors (the text on which you apply the link to go to next work).
You can skip using an editable, so you could simply use instead
Code: Select all
<cms:get_custom_field 'text_for_next_article' masterpage='globals.php' />
just your text for navigating to the next article: Next work
6 posts Page 1 of 1