Forums

[resolved] Listing sub-pages under main menu when on parent page or on other sub-page (5 posts)

  1. robcub
    Member
    Posted 1 year ago #

    Hello, I have been trying to sort this out with various snippets from the codex but they just list all pages.

    I have a site that has several pages with child pages (no grandchildren). The sub-pages or child pages have their parent page specified with the drop-down under Page Attributes in the page editing area.

    I just want to list all the subpages of a particular parent page listed as links under the main navbar when either on the parent page or on one of the child pages of that parent.

    Can anyone point me towards the PHP for this? I would be very grateful.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

  3. robcub
    Member
    Posted 1 year ago #

    Thank you, esmi, I've tried all those snippets and they just list out all the pages regardless. I think it may be because I'm using a Genesis child theme and inserting the code with Simple Hooks plugin.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Quite possibly. They work as coded solutions in all of the themes that I've made.

  5. robcub
    Member
    Posted 1 year ago #

    I needed to add "global $post;"

    You should add "global $post;" before you try to use $post inside a function (simple hooks executes within a function), apparently. I don't know why it works but it works.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic