admin管理员组

文章数量:1296858

I am using the code bellow to display a list of Child Pages on a Parent Page. I want to order the displayed list by Alphabetical order. How can I achieve this?

function wpb_list_child_pages() { 
 
    global $post; 
 
    if ( is_page() && $post->post_parent )
 
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    else
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
 
    if ( $childpages ) {
 
        $string = '<ul>' . $childpages . '</ul>';
    }
 
    return $string;
 
}
 
add_shortcode('wpb_childpages', 'wpb_list_child_pages');

I am using the code bellow to display a list of Child Pages on a Parent Page. I want to order the displayed list by Alphabetical order. How can I achieve this?

function wpb_list_child_pages() { 
 
    global $post; 
 
    if ( is_page() && $post->post_parent )
 
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    else
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
 
    if ( $childpages ) {
 
        $string = '<ul>' . $childpages . '</ul>';
    }
 
    return $string;
 
}
 
add_shortcode('wpb_childpages', 'wpb_list_child_pages');
Share Improve this question edited Apr 16, 2021 at 16:06 Antti Koskinen 5,9838 gold badges15 silver badges26 bronze badges asked Apr 14, 2021 at 13:41 SkinzSkinz 1
Add a comment  | 

1 Answer 1

Reset to default 0

Take a look at the documentation of wp_list_pages(). You can use the argument sort_column to specify the ordering. Use sort_column=post_title to list the pages alphabetically.

So your query for the child pages will become something like this:

$childpages = wp_list_pages( 'sort_column=post_title&title_li=&child_of=' . $post->post_parent . '&echo=0' );

本文标签: phpOrder by title Child Pages displayed in a Parent Page