Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
12 posts Page 2 of 2
The pages are by default sorted by their dates so that is not an issue.

In our previous conversation where I suggested that you use this particular code (viewtopic.php?p=19809#p19809), I had mentioned that you'll have to tweak it to include folder=k_page_foldername

The problem you are seeing is because that parameter is missing from the cms:pages statement that fetches all IDs into an array
$page_ids = explode( ",", "<cms:pages ids_only='1' />" );

Because of it, the array always contains IDs of *all* the pages - this obviously will fail when you are trying to show only images that belong to a particular folder.

Coming to the solution - I'll assume, as is the norm with galleries, that in the 'list-view' you are displaying images residing immediately within a folder (i.e. not displaying the images that are in the sub-folders also). In which case, your list-view code should look something like this -
Code: Select all
<cms:pages folder=k_folder_name include_subfolders='0' limit='18' paginate='1'>

So while displaying a page-view (i.e. a single image) you'll want to restrict navigation to sibling pages that reside in the same folder as that of the current page.
Following is a simplified pag-view code that does just that. I have tested it out and it is working perfectly for folders, sub-folders etc.
Code: Select all
<cms:if k_is_page >
        global $CTX;
        $page_ids = explode( ",", "<cms:pages folder=k_page_foldername include_subfolders='0' 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' );

    <!-- show single image -->
    <img alt="<cms:show k_page_title />" src="<cms:show gg_image />"/>
    <!-- show links to next and prev images -->
    <cms:if prev_page_id >
        <cms:pages id=prev_page_id skip_custom_fields='1'>
            <a href="<cms:show k_page_link />">Prev</a>
    <cms:if next_page_id >
        <cms:pages id=next_page_id skip_custom_fields='1'>
            &nbsp;<a href="<cms:show k_page_link />">Next</a>

The only change to the original code is this where we have taken into consideration the current folder -
$page_ids = explode( ",", "<cms:pages folder=k_page_foldername include_subfolders='0' ids_only='1' />" );

As I said, the code above is tested. So I suggest you please first use it without any modifications. Once you are satisfied that it works properly, make the changes to your own code.

Hope it helps.
KK saving me again! Thanks so much for the help!
12 posts Page 2 of 2

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests