Função wp_list_pages

Função para listar páginas irmãs:

function combox_list_sister_pages() {

global $post;

$childpages = '';

$string = '';

$post_data = get_post($post->post_parent);

$parent_id = $post_data->ID;if ( is_page() && $post->post_parent )

$childpages = wp_list_pages( 'sort_column=post_title&depth=1&title_li=&child_of=' . $parent_id . '&echo=0&exclude=' . $post->ID);
else
$childpages = wp_list_pages( 'sort_column=post_title&depth=1&title_li=&child_of=' . $post->ID . '&echo=0&exclude=' . $post->ID );

if ( $childpages ) {

$string = '<ul>' . $childpages . '</ul>';
}

return $string;
}

Função para listar páginas filhas:

/**
* Get all children from page ID
* Return a unorderd list
*
*/

function combox_list_child_pages() { 
global $post;
$childpages = '';
$string = '';

if ( is_page() && $post->post_parent )

$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0&exclude=' . $post->ID);
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0&exclude=' . $post->ID );

if ( $childpages ) {

$string = '<ul>' . $childpages . '</ul>';
}

return $string;
}

Para ordenar a listagem de páginas:

‘sort_column’
(string) Comma-separated list of column names to sort the pages by. Accepts ‘post_author’, ‘post_date’, ‘post_title’, ‘post_name’, ‘post_modified’, ‘post_modified_gmt’, ‘menu_order’, ‘post_parent’, ‘ID’, ‘rand’, or ‘comment_count’. Default ‘post_title’.

Mais info:

https://developer.wordpress.org/reference/functions/wp_list_pages/

Deixe uma resposta