Cycling through grandchildren pages
-
I’ve got a set up of 3 tiers of pages in the site structure. A bit like this:
- Home
- Category
- Section
- Page of content
- Another page of content
- Another section
- More content
- Category 2
- A section in here
- Even more pages
I’ve got a link at the bottom of the pages of content to the next page. What I want to do is to bridge the gap between the sections and also the categories. So when you get to the bottom of “Another page of content” you get a link to go to “More content”. Also at the bottom of “More content” there is a link to “Even more pages”. Effectively all of the grandchildren pages.
This is what I’m using for the “Next” link within the same parent:
<?php $pagelist = get_pages('sort_column=menu_order&sort_order=asc&child_of='.$post->post_parent); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $nextID = $pages[$current+1]; $nexttitle = get_the_title($nextID); ?> <?php if (!empty($nextID)) { ?> Next: <a href="<?php echo get_permalink($nextID); ?>"><?php echo $nexttitle ?></a> <?php } ?>
This is a bit long winded, I hope it makes sense – I hope someone can help me!! Thanks.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Cycling through grandchildren pages’ is closed to new replies.