WordPress.org

Ready to get started?Download WordPress

Forums

Sub-Pages in list form on Parent Page's Body (11 posts)

  1. Shockenaw
    Member
    Posted 4 years ago #

    Hey guys,

    May be a simple question for you to answer but....

    In my website I want to have in the navigation menu only the links to my parent pages (which I do).. HOWEVER, I am not sure how to get the Sub-Pages in an alphabetical list in the body of the parent page.

    Any Ideas?

    [moderated--bump removed. Please refrain from bumping as per Forum Rules]

  2. MichaelH
    Member
    Posted 4 years ago #

    For your Page Template

    <?php
    $parent_id = $posts[0]->ID;
    $args=array(
      'post_parent' => $parent_id,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. Shockenaw
    Member
    Posted 4 years ago #

    Alright so in that code I should change post_parent' => $parent_id ?

    I apologize I am just confused with this (newb)

  4. MichaelH
    Member
    Posted 4 years ago #

    Not sure what you are asking, but in a Page Template, $posts[0]->ID would be the ID of the queried page.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  5. Shockenaw
    Member
    Posted 4 years ago #

    With my website, I am trying to get it to list Sub Pages alphabetically in the body of the Parent Page..

    Ex..

    The Genre is Rock..

    In Rock it would have an alphabetical list following.

    a
    b
    c
    d
    etc..

  6. Shockenaw
    Member
    Posted 4 years ago #

    I just implement the above code into my page.php file? Or is there tweaking that needs to be done? Like my metal id page =33

    Do I have to tweak code to get it to list the sub pages of page 33? (metal)

  7. MichaelH
    Member
    Posted 4 years ago #

    I just implement the above code into my page.php file?

    Yes.

    Do I have to tweak code to get it to list the sub pages of page 33? (metal)

    If you are accessing the metal page, then that should suffice:

    $parent_id = $posts[0]->ID;
  8. Shockenaw
    Member
    Posted 4 years ago #

    I still can not get the code to show anything.. It would be great if you could contact me via email and help me out! [email moderated]

  9. MichaelH
    Member
    Posted 4 years ago #

    Please paste all the code from the theme Page Template file your are working with, into a pastebin such as wordpress.pastebin.com, and report the link back here. Maybe someone can spot your problem. Thanks.

  10. dennislynge
    Member
    Posted 4 years ago #

    Hey MichaelH,

    I used the code above and it works like a dream. There is just one problem I somehow can't figure out.
    How do I keep the sub-pages showed aswell as on the parent page?

    http://www.dennislynge.dk/clients/poesienshus/?page_id=2

  11. khushalbhadra
    Member
    Posted 3 years ago #

    I too have a website http://www.gospelofdoom.in in which i have mentioned bands alphabetically and planning to learn how can I do this in WordPress. Like Shockenaw pointed out to liste the sub pages like

    Genre of Rock and below mentioned in alphabetical order. I do not want my blog post to display alphabetically but I need my sub pages to be displayed alphabetically.

    Any help on this would be appreciated. I am not a PHP programmer but I do understand the process the workflow of PHP. So a detailed tutorial would be of a help.

Topic Closed

This topic has been closed to new replies.

About this Topic