There appears to be a major flaw with this otherwise speedy loading code: you can't reorder pages without messing up the navigation

I just found this bug today, I reordered my gallery and pages that should have had next links didn't have them, others were missing previous page links, and some even miss all navigation links.
Any ideas on what can be done to fix this?
KK wrote: One more solution -
This one will work from Couch 1.3 onwards.
Looping through all the pages to find the next and prev is likely to take a performance hit if the number of pages is large. To avoid this we use PHP in this solution.
- 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 />">Prev</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 />">Next</a>
</cms:pages>
</cms:if>
Hope this helps.
ADDENDUM:
Some related links of interest:
viewtopic.php?f=2&t=21viewtopic.php?f=4&t=7457viewtopic.php?p=16084#p16084