• davidandre

    (@davidandre)


    Hi everybody!
    i am back on the forum as i need your help again!
    this time seems to be easier but i am lost again:)

    i want the subpage of the active page (and only this one)to be displayed
    in this way:
    if i am on the page 1:
    page1
    subpage1 of page 1
    subpage2 of page1
    page 2
    page 3

    but if iam on page 2:
    page 1(no submenu displayed)
    page 2
    subpage1 of page 2
    subpage2 of page 2
    page 3

    i would prefer no to use plugin if possible..

    i ve been watching le codex wp_list_pages for a while but didn t find any answer to this specific case.

    thanks a lot,

    bye ,
    David

Viewing 10 replies - 1 through 10 (of 10 total)
  • MichaelH

    (@michaelh)

    You’ll need to use Function_Reference/get_pages for that.

    Thread Starter davidandre

    (@davidandre)

    Hi michael!
    thanks a lot for the advice.
    But i guess i don t know how to use this function.
    now it doesnt display anything on my menu:(

    is thit like that?:
    <?php
    $pages = get_pages(‘child_of=’.$post->ID.’&sort_column=post_date&sort_order=desc’);?>

    what am i doing wrong?
    and i would like the pages and sub pages displayed as “tree”

    if you have an idea i would appreciate:)) a lot

    cheers for the answer

    Thread Starter davidandre

    (@davidandre)

    oh i forgot!
    this this the code i am using, just in case:it is working well but showw all subpages even if not current page.and i need just the subapage of the current page:

    <?php if ( is_page() ) {
    if($post->post_parent)
    $children = wp_list_pages(‘sort_column=menu_order&title_li=&child_of=’.$post->post_parent.’&echo=0′);
    else
    $children = wp_list_pages(‘sort_column=menu_order&title_li=&child_of=’.$post->ID.’&echo=0′);
    if ($children) {
    ?>
    <div class=”sidebar”>
    <h2></h2>
    <ul id=”sub”>
    <?php echo $children; ?>

    </div>
    <?php
    } // End If Post
    } // End if is page
    ?>

    MichaelH

    (@michaelh)

    <?php
    if ( is_page() ) {
      $pages = get_pages();
      foreach($pages as $page) {
        if ($page->post_parent == 0 || $page->post_parent == $posts[0]->ID ) {
        ?>
          <p><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></p>
        <?php
        }
      }
    }
    ?>
    Thread Starter davidandre

    (@davidandre)

    Hi michael!
    i ve just try and i doesnt work as i would like.It shows me all the parent, no child but the grand childs..?

    1/ where could $children = wp_list_pages(‘sort_column=menu_order&title_li=&child_of=’.$post->post_parent.’&echo=0′); i add something like that in this code.

    2/with the code i use (that i send you in my second post) i am very close to the target, but it shows me all childpages even if not current page!

    what could i change in this code to fix that?

    sorry to be such a pain:) i am learning and hoppefully i ll do better soon.
    a big thanks for your answers

    MichaelH

    (@michaelh)

    I don’t think wp_list_pages is not going to do what you want.

    The code I presented will display all pages that are parent pages or will show the child pages of the current visited page. It will not list grandchildren.

    I just put that code at the top of the pages.php using the WordPress Default themes wp-content/themes/default/pages.php file so try using that theme

    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    
    get_header(); ?>
    
    	<div id="content" class="narrowcolumn" role="main">
    <?php
    //display all pages but only subpages if this is a parent page
    if ( is_page() ) {
      $pages = get_pages();
      foreach($pages as $page) {
        if ($page->post_parent == 0 || $page->post_parent == $posts[0]->ID ) {
        ?>
          <p><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></p>
        <?php
        }
      }
    }
    ?>
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    	<?php comments_template(); ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
    Thread Starter davidandre

    (@davidandre)

    wahoo!
    Thanks a lot!
    really appreciate!
    i ll try it right away
    cheers!

    Thread Starter davidandre

    (@davidandre)

    Ok i am closer but i didnt explain me well enough. I ll show you the bach end and it will make thing more clear:

    home
    admin
    0
    05/03/2010
    Publicada

    Home-catalan
    David
    0
    10/03/2010
    Publicada

    menu contenido
    admin
    0
    04/03/2010
    Publicada

    — acceso usuarios
    admin
    0
    04/03/2010
    Publicada

    — contactar
    David
    0
    04/03/2010
    Publicada

    — descargas
    admin
    0
    04/03/2010
    Publicada

    — enlaces
    admin
    0
    04/03/2010
    Publicada

    — noticias
    David
    0
    hace 24 horas
    Publicada

    menu contenido catala
    David
    0
    10/03/2010
    Publicada

    — contactar catala
    David
    0
    10/03/2010
    Publicada

    — descargas catala
    David
    0
    10/03/2010
    Publicada

    menu header
    admin
    0
    04/03/2010
    Publicada

    — compa?eros de viaje
    admin
    0
    04/03/2010
    Publicada

    — mediación ambiental
    admin
    0
    04/03/2010
    Publicada

    — — conflictos
    David
    0
    08/03/2010
    Publicada

    — — prueba
    David
    0
    hace 16 horas
    Publicada

    — qué ofrecemos
    David
    0
    04/03/2010
    Publicada

    — — subpagina
    Editar | Edición rápida | Papelera | Ver
    admin
    0
    hace 4 horas
    Publicada

    — quienes somos
    David
    0
    10/03/2010
    Publicada

    menu header catala

    And i would like the menu to show just the menu header (but this item “menu header” Id=399 should not appears) and all the sub pages which is 4pages =”compa?eros de viajes, mediacion ambiental,quienes somos,que ofrecemos” ans now
    the grandchils should appear only if the child “compa?eroa de viaje o quienes somos….” is current page

    I really hope you understand me. to resume the page should not appear but just the child pages o the page Id=399 and, the gran child just appear if their parent (which is one of the 4 childs of Id =399) is current page!!!

    ouf hard to explain..
    i don t want to abuse to your patience but if you could give me the last advice it would be very very appreciated. by my own it will be too tough.

    thanks a lot!!!

    MichaelH

    (@michaelh)

    Again, this does not work with grandchild pages–only parent and child

    So here’s how it works assuming these pages:
    # Page1
    # Page2
    ## Page2child1
    ## Page2child2
    # Page3
    ## Page3child
    # Page4

    If you visit Page1 you will see
    # Page1
    # Page2
    # Page3
    # Page4

    If you visit Page2 you will see
    # Page1
    # Page2
    ## Page2child1
    ## Page2child2
    # Page3
    # Page4

    The # signs are for reference only–you won’t see those

    Thread Starter davidandre

    (@davidandre)

    ok Michael!
    i ll try to find out.
    thanks a lot for your help and your time,

    cheers!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘sub page of the current page’ is closed to new replies.