0

I'm using a dropdown menu on my Wordpress page which shows all the pages. If you hover over it, the subpages of that particular page are shown. Say I have five pages that each have a couple of subpages. Is it possible to show the subpages on the same page as the page itself and have the dropdown menu link to the section of the page where the subpage is listed?

Hope this is clear. thanks.

1

get_children is the most straightforward way to get "attachments, revisions, or sub-Pages". So...

$children = get_children(array('post_parent'=>$post->ID));
if (!empty($children)) {
  foreach ($children as $child) {
    echo '<div id="child-'.$child->ID.'" >';
      // content formatted however you want
    echo '</div>';
}

See the Codex page for further parameters that you might need.

I don't know how you've constructed your drop-down menu but you can link to any element on the page using its id attribute so your href for the links should be #child-<ID>, preferably constructed as an absolute URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.