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 1 of 2
Hey there,
I tried to find right solution for my problem but I couldnt find. I have a clonable template which is manually reordered. I want to show previous & next post in page-view. I use the code below but it didn't work. Can you help me please?
Code: Select all
<div id="single-pagination" class="portfolio-pagination">
                <ul class="pagination">
                <cms:pages stop_before=k_page_date limit='1'>
                    <li class="prev"><a href="<cms:show k_page_link />" title="<cms:show k_page_title />">Previous<span class="icon"></span></a></li>
                </cms:pages>
                    <li class="back"><a href="/works.php" title="All Works"><span class="icon"></span></a></li>
                <cms:pages start_on=k_page_date order='asc' limit='1' offset='1'>
                    <li class="next"><a href="<cms:show k_page_link />" title="<cms:show k_page_title />">Next<span class="icon"></span></a></li>
                </cms:pages>
                </ul>
            </div>
I will suggest 2 different solutions -

(1) is based on KK's code viewtopic.php?f=8&t=7087#p9408 It helps if the number of pages is not in thousands, because it goes through all pages to find the right ones. Key factor is to have orderby='weight' in cms:pages.

(2) Second solution I created and tested on a larger number of pages (100k) to make sure it works blazing fast. It is based on taking 2 next / prev pages directly from the database. It is the fastest and also helps with custom styling because relevant page's data is available within page_prev / page_next blocks.

Does it help?

My Documentation, Addons, Functions.
Join COUCH telegram channel
Hi @trendoman, I have 20 page so I tried first solution and it works great. In my code I also use "title tag" to show next and previous page name as a tooltip. But there is a problem.
For example when I visit page A; next and previous title show page A again. Where do I wrong?
Thanks.
It is because the first code doesn't 'remember' page title in a separate variable. Try the second code or add a new variable alongside the existing one in the first code, for example -
Code: Select all
<cms:set prev_page=k_page_link 'global' />
<cms:set prev_page_title=k_page_title 'global' />

Then use it in the output of the navigation. It is not very comfortable for me personally, so I made a second sample and left a comment about styling. Does it solve the problem?

My Documentation, Addons, Functions.
Join COUCH telegram channel
I used the existing code and add new variable. And the problem is solved. You are great trendoman :))
Thank you so much
You are welcome :)

My Documentation, Addons, Functions.
Join COUCH telegram channel
The second solution looks like just what I need for a project, so I tried it out and ran into an issue. I have four pages, and on Page 1, both the Previous and Next links disappear, leaving the viewer stranded. Pages 2-4 work just fine, though. I didn't edit the code in any way; I just slapped it into a template as-is to give it a test run.

As a side note, is there a way to stop the Prev/Next links from disappearing when on the first or last page? I'd like to be able to style them myself rather than just have them vanish on me completely.
sterre wrote: The second solution looks like just what I need for a project, so I tried it out and ran into an issue. I have four pages, and on Page 1, both the Previous and Next links disappear, leaving the viewer stranded. Pages 2-4 work just fine, though. I didn't edit the code in any way; I just slapped it into a template as-is to give it a test run.

As a side note, is there a way to stop the Prev/Next links from disappearing when on the first or last page? I'd like to be able to style them myself rather than just have them vanish on me completely.



Any solution?? This is exactly what I ran into and can't find a solution..
francisknightley wrote: Any solution?? This is exactly what I ran into and can't find a solution..

This is the solution (for the code snippet #1) -
Code: Select all
<ul>
    <cms:if prev_page>
        <li><a href="<cms:show prev_page />">Prev</a></li>
    <cms:else />
        <li class="first">no prev</li>
    </cms:if>
    <cms:if next_page>
        <li><a href="<cms:show next_page />">Next</a></li>
    <cms:else />
        <li class="last">no next</li>
    </cms:if>
</ul>


My Documentation, Addons, Functions.
Join COUCH telegram channel
trendoman wrote:
francisknightley wrote: Any solution?? This is exactly what I ran into and can't find a solution..

This is the solution (for the code snippet #1) -
Code: Select all
<ul>
    <cms:if prev_page>
        <li><a href="<cms:show prev_page />">Prev</a></li>
    <cms:else />
        <li class="first">no prev</li>
    </cms:if>
    <cms:if next_page>
        <li><a href="<cms:show next_page />">Next</a></li>
    <cms:else />
        <li class="last">no next</li>
    </cms:if>
</ul>




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.
15 posts Page 1 of 2