Load parent pages when there are no child pages

possible code: <?php $children = wp_list_pages(‘title_li=&child_of=”.$post->ID.”&echo=0&depth=1’); if ($children) { ?> <ul id=”three-menu”> <?php echo $children; ?> </ul> <?php } //ends (if($children)// elseif($post->post_parent) { //if no children, try to get parent page and show siblings pages including the page itself $siblings = wp_list_pages(‘title_li=&child_of=”.$post->post_parent.”&echo=0&depth=1’); if ($siblings) { ?> <ul id=”three-menu”> <?php echo $siblings; ?> </ul> <?php } … Read more

Add class to the items in wp_list_pages

As wp_list_pages() has an argument of walker, you can use that to replace what is being used by walk_page_tree() as walker class internally. @Brady has left a nice example in this answer. class WPSE113482PageWalker extends Walker_Page { function start_el( &$output, $page, $depth, $args, $current_page ) { // Build $output here and apply your class for … Read more

get all page IDs from wp_list_pages

wp_list_pages() is for formatted markup. Use get_pages() and wp_list_pluck(): $pages = get_pages( array ( ‘parent’ => 0, // replaces ‘depth’ => 1, ‘exclude’ => ‘3,5,11’ ) ); $ids = wp_list_pluck( $pages, ‘ID’ ); $ids holds an array of page IDs now.

Add Parent to List of Subpages

If I understand what you want, it is trickier than it should be to get it working. $ancestors = array(); $ancestors = get_ancestors($post->ID,’page’); $parent = (!empty($ancestors)) ? array_pop($ancestors) : $post->ID; if (!empty($parent)) { $pages = get_pages(array(‘child_of’=>$parent)); if (!empty($pages)) { $page_ids = array(); foreach ($pages as $page) { $page_ids[] = $page->ID; } $children = wp_list_pages(“include=”.$parent.’,’.implode(‘,’,$page_ids).”&echo=1″); echo … Read more

How can I list all pages with their templates?

https://codex.wordpress.org/Function_Reference/get_page_template_slug a basic query to get all pages, sorted by title, then output page title and template file name: $args = array( ‘post_type’ => array( ‘page’ ), ‘order’ => ‘ASC’, ‘orderby’ => ‘title’ ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<p>’; the_title(); echo … Read more

How to List All Pages (With their template names) Within a Website

Not so hard as you expected. Try this: global $wpdb; $sql = “SELECT post_title, meta_value FROM $wpdb->posts a JOIN $wpdb->postmeta b ON a.ID = b.post_id WHERE a.post_type=”page” AND a.post_status=”publish” AND b.meta_key = ‘_wp_page_template’ “; $pages = $wpdb->get_results($sql); echo ‘<pre>’; print_r($pages); echo ‘</pre>’;

How can I hide children of draft pages using wp_list_pages()?

Great answers above. I took on the challenge trying to find yet another way to solve this. The exclude parameter: We could try: ‘exclude’ => wpse_exclude_drafts_branches() where: function wpse_exclude_drafts_branches() { global $wpdb; $exclude = array(); $results = $wpdb->get_col( “SELECT ID FROM {$wpdb->posts} where post_status=”draft” AND post_type=”page” ” ); $exclude = array_merge( $exclude, $results) ; while … Read more