I’ve this pages structure:
-
TOP PAGE
- SUB PAGE 1
- SUB SUB PAGE 1
- SUB PAGE 2
[etc]
- SUB PAGE 1
Is it possible to display on each sub page a link to come back to the top level page? And how?
I’ve this pages structure:
TOP PAGE
[etc]
Is it possible to display on each sub page a link to come back to the top level page? And how?
Comments are closed.
Here’s a way to get the top page url:
where
get_ancestors()
returns an array containing all the parents (ID) of the given page. You can read more about it in the Codex here.Here are various ways to get the last array item, but note that
end()
doesn’t expects a function as an input – more about it in the PHP docs here.You can get the post ID of the parent page with
$post->post_parent
; at that point, it’s just a matter of using that ID to get the permalink.This snippet from the wp.org forums will do what you need:
Code snippet found here.