Shockenaw
Member
Posted 2 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]
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().
?>
Shockenaw
Member
Posted 2 years ago #
Alright so in that code I should change post_parent' => $parent_id ?
I apologize I am just confused with this (newb)
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
Shockenaw
Member
Posted 2 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..
Shockenaw
Member
Posted 2 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)
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;
Shockenaw
Member
Posted 2 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]
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.
dennislynge
Member
Posted 2 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
khushalbhadra
Member
Posted 1 year 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.