WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Unique menu for one page and children pages. (3 posts)

  1. saitarion
    Member
    Posted 2 years ago #

    I am currently using the below code to generate a secondary menu within the pages:
    page_parent_1
    page_child_1
    page_child_2

    Is it possible to set it up so that it will create the menu in the parent 'page_parent_1' and automatically add to all the children without adding every child page id or slug to the <?php ... ?> code.

    <?php if ( is_page( array( 'page_parent_1', 'page_child_1', 'page_child_2' )) ) {echo wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'secondary' ) ) ;} ?>

    I have tried using && $post->post_parent & get_page_children but have had no luck.

    Any help is appreciated!

  2. Curtiss Grymala
    Member
    Posted 2 years ago #

    I would use something like the following:

    <?php
    global $post;
    /* Replace "12" with the ID of page_parent_1 */
    if( 12 === $post->ID || 12 === $post->post_parent ) {
    /* Do your menu stuff here */
    }
    ?>
  3. saitarion
    Member
    Posted 2 years ago #

    Thank you very much. That works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic