Do Not Display Parent Page if No Subpages

Personally, I think this is the neatest, least intensive (database querying) solution: <?php $parentid = $post->post_parent ? @ array_pop( get_post_ancestors( $post ) ) : $post->ID; $children = wp_list_pages( array( “child_of’ => $parentid, ‘title_li’ => ”, ‘echo’ => false, ) ); if ( $children ) : ?> <ul class=”subpages”> <li><a href=”https://wordpress.stackexchange.com/questions/135921/<?php echo get_permalink( $parentid ) ?>”><?php … Read more

Custom category listings

WordPress automatically creates an archive for each category. If you look in wp-admin, under Posts > Categories, you can click “view” to view a category and that will show you what it looks like and what the URL is. It is possible that a theme could override this functionality, but it’s unlikely. Most themes have … Read more

wp_list_pages – Using a Walker to customize output order

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages. Let’s say you call wp_list_pages() like this: wp_list_pages( array( ‘please_filter_me’ => TRUE ) ); You can sort the pages now with code like this (not tested): add_filter( ‘get_pages’, function( $pages, $args ) { // not our query … Read more

Setting multiple values to as sort_column

get_pages explodes sort_column on the comma (,) character. Just check the source: foreach ( explode( ‘,’, $sort_column ) as $orderby ) { So the correct format should be the first one you posted: $args = array( ‘sort_order’ => ‘ASC’, ‘sort_column’ => ‘menu_order, post_title’ ); $children = get_pages($args); If you are not seeing the ordering you … Read more

create shortcode to show children if any otherwise siblings

Yes, you’re close. What you want is something like this: function rt_list_children() { global $post; $output=””; if ( $post->post_parent ) { // if it’s a child page $siblings = wp_list_pages( array( ‘child_of’ => $post->post_parent, ‘title_li’ => ”, ‘echo’ => ‘0’, ) ); if ( $siblings ) { // it has siblings $children = $siblings; } … Read more