Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
15 posts Page 2 of 2
francisknightley wrote: I did this and it works fine except for the first post (post1) of all: it doesn't display the next one (post2) which is strange.

Something wrong in your template code. Zip and I can test it.
@trendoman it's happening between lines 242 and 309

On my first post is outputing:

<p>SHOW LAST POST (because this one is the 1st)</p>
<p>SHOW FIRST POST (because this one is the last)</p>

Attachments

francisknightley wrote: @trendoman it's happening between lines 242 and 309

Okay, I saw the code briefly. Template has the code from script#2, while my solution above was provided for script#1 (simpler one, based on cms:pages, not cms:query). Can you just use the #1? Or the number of posts is large that a direct query is warranted? I mean #2 is for real kick-ass power users.. in 99% cases simple script works perfectly.
Ok, so I almost got it. It's linking to 'next' and 'previous' page as expected!

Sorry but just to wrap it up I have a final question:
How do I identify all the items associated with each singular "prev_page" and "next_page" like:
— 'thumb' for thumbnail image
— 'en_title' for page title
— etc… ?

Because now it's displaying this items but from the page I'm currently seeing.
I know I have to identity the "prev_page" and "next_page" inside the "<cms:pages limit='1'>", but.. how?
my code:

Code: Select all
<cms:set cur_page=k_page_name 'global' />
<cms:set prev_page='' 'global' />
<cms:set next_page='' 'global' />
<cms:set found_cur_page='0' 'global' />

<cms:pages skip_custom_fields='1' orderby='weight' order='asc'>
   <cms:if found_cur_page=='0' >
      <cms:if k_page_name==cur_page >
         <cms:set found_cur_page='1' 'global' />
      <cms:else />
         <cms:set prev_page=k_page_link 'global' />
      </cms:if>
   <cms:else />
      <cms:if next_page==''>
         <cms:set next_page=k_page_link 'global' />
      </cms:if>
   </cms:if>
</cms:pages>

<cms:if prev_page>
<cms:pages limit='1'>
            <div class="col-lg-6 col-sm-6">
                    <a href="<cms:show prev_page />" class="portfolio-box">
                        <img src="<cms:show thumb />" class="img-responsive" alt="">
                        <div class="portfolio-box-caption">
                            <div class="portfolio-box-caption-content">
                               <h5>Previous Project</h5>
                               <h4><cms:show en_title /></h4>
                            </div>
                        </div>
                    </a>
                </div>
</cms:pages>
</cms:if>
       
                     
<cms:if next_page> 
<cms:pages limit='1'>
                <div class="col-lg-6 col-sm-6">
                    <a href="<cms:show next_page />" class="portfolio-box">
                        <img src="<cms:show thumb />" class="img-responsive" alt="">
                        <div class="portfolio-box-caption">
                            <div class="portfolio-box-caption-content">
                               <h5>Next Project</h5>
                               <h4><cms:show en_title /></h4>
                            </div>
                        </div>
                    </a>
                </div>
</cms:pages>
</cms:if>   
You wrapped correctly.

Change to k_page_id first -
Code: Select all
<cms:set prev_page=k_page_link 'global' /> --> <cms:set prev_page=k_page_id 'global' />

Then use that id -
Code: Select all
<cms:if prev_page>
<cms:pages limit='1'> --> <cms:pages limit='1' id=prev_page>
            <div class="col-lg-6 col-sm-6">
                    <a href="<cms:show prev_page />" class="portfolio-box"> -->  <a href="<cms:show k_page_link />" class="portfolio-box">
15 posts Page 2 of 2