WordPress.org

Ready to get started?Download WordPress

Forums

Pages menu (2 posts)

  1. TimCe
    Member
    Posted 7 years ago #

    I'm looking for a way to make a sort of menu for this structure:

    Main page 1
    ==> sub page
    ==> sub page
    Main page 2
    ==> Sub page of 2

    I've tried a couple of things but I seem to be missing something. The basic idea is to show all subpages of page 1 when you're on main page 1 or one of it's subpages. And The same for 2.

    Hope that explains it a bit, any help would be greatly appreciated :-)

  2. TimCe
    Member
    Posted 7 years ago #

    Nevermind, I found how :-)

    <?php
    global $wp_query;
    
    if( empty($wp_query->post->post_parent) ) {
    $parent	= $wp_query->post->ID;
    $main_title	= $wp_query->post->post_title;
    } else {
    $parent	= $wp_query->post->post_parent;
    $main_title	= get_the_title($post->post_parent);
    }
    
    if(isset($parent)){
    ?>
    					<h2><?php echo $main_title; ?></h2>
    					<ul id="submenu">
    					<?php
    						wp_list_pages("title_li=&child_of=$parent");
    					;?> 
    
    <?php
    }?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags