I'm using WordPress as CMS for a site I'm developing. When I'm browsing posts, I can use Next/Previous links to walk between posts. I want to have the same thing on pages.
- Page A
- Page B
- Page C
Page A should link to next sibling Page B. Page B should link to previous sibling Page A and next sibling Page C. Page C should link to previous sibling Page B.
Is there any plugin you can recommend that generates these links? I know there are some plugins that do this, but I specifically want one that hooks into my current theme automatically. I know how to edit the theme, but that would brick my site whenever a theme update is available.
I'm using the LightWord WordPress theme.
from the wordpress Codex
Pop the following code into your functions.php file in your active theme directory:
To call the function:
or
and it will echo out the link to the previous or next page.
If you want both you can leave the function empty and it will return an array with both links.
Here another function based on jackreichert's answer. With the added functionality that this wraps around to the last/first sibling when you are at the end of the list of siblings, so you can loop around endlessly. It also uses the menu order.
After trying several solutions, doing my best not to install another plugin, in the end the only thing that worked was a free plugin: Next Page, Not Next Post.
(I had issues with the solutions given here, I think perhaps because I manually order the pages in the Pages section of Wordpress Admin. You can select page order manually. So my first page in the hierarchy might have an ID of 100, and the second page might have an ID of 10. The page ID is not how my pages get ordered.)
A rough snippet of what I developed onwards from the answers here (to get a real link and the post title in action) - might prove helpful to someone!
and then use as this: