Hey Guys,
I’m trying to build pagination links for the next/previous cousin page. For example, my page structure is like this:
- Top Level
- A
- a1
- a2
- B
- b1
- b2
- A
When I’m on a2, I want the ‘Previous Page’ link to go to a1, but the ‘Next Page’ link to go to b1 (skipping B).
I’m using great Next Page, Not Next Post plugin at the moment, but it can only go to next page (so it would include B in the above example).
I’m trying to modify it to only show cousins, but running into some trouble. So far I have this:
// query gand parent page level, go to next parent page, and then loop to find it's next child, eke!
// get grandparent id
$parentInfo = get_page($post->post_parent);
// query the level above's pages
// $getParentPages = get_pages('child_of='.$parentInfo->post_parent.'&parent='.$parentInfo->post_parent.'&'.$getPagesQuery);
$getParentPages = get_pages($getPagesQuery);
$parentPageCount = count($getParentPages);
for($pp=0; $pp < $parentPageCount; $pp++) {
// get the array key for our entry
// if ($post->post_parent == $getParentPages[$pp]->ID) break;
if ($post->ID == $getParentPages[$pp]->ID) break;
}
// assign our next key
$parentNextKey = $pp+1;
if (isset($getParentPages[$parentNextKey])) {
$anchorName = $getParentPages[$parentNextKey]->post_title;
$output = '<a href="'.get_permalink($getParentPages[$parentNextKey]->ID).'" title="'.$anchorName.'">';
}
So how would I make that skip B, and go to b1 and so on?
Thanks for the help!
-Drew
I solved this by getting all pages, assigning them by level, and then getting the next page of the same level. If you also want the previous page then you should probably cache the functionality that groups the pages by level.