how to properly list child pages in sidebar?

Here is the code that satisfies all your 3 requirements above. <?php /* * get_page_depth * Gets the page depth, calls get_post on every iteration * https://gist.github.com/1039575 */ if ( !function_exists( ‘get_page_depth’ ) ) { function get_page_depth( $id=0, $depth=0 ) { global $post; if ( $id == 0 ) $id = $post->ID; $page = get_post( … Read more

Only allow new subpages to be created

Code based in Bainternet’s answer to this question: Make Categories and Tags required in admin See code comments. add_action( ‘admin_head-post-new.php’, ‘wpse_59770_publish_admin_hook’ ); add_action( ‘admin_head-post.php’, ‘wpse_59770_publish_admin_hook’ ); add_action( ‘wp_ajax_wpse_59770_pre_submit_validation’, ‘wpse_59770_ajax_pre_submit_validation’ ); function wpse_59770_publish_admin_hook() { global $current_screen; if( ‘page’ != $current_screen->post_type ) return; ?> <script language=”javascript” type=”text/javascript”> jQuery(document).ready(function() { jQuery(‘#publish’).click(function() { var form_data = jQuery(‘#parent_id’).val(); form_data = … 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

Display child pages on a parent and child page using Featured Thumbnails

Use get_ancestors to get the page parent, then get the children of that parent. $ancestors = array(); $ancestors = get_ancestors($post->ID,’page’); $parent = (!empty($ancestors)) ? array_pop($ancestors) : $post->ID; if (!empty($parent)) { $kids = new WP_Query( array( ‘post_parent’=>$parent, ‘post_type’ => ‘page’, ‘ignore_sticky_posts’ => true ) ); if ($kids->have_posts()) { while ($kids->have_posts()) { $kids->the_post(); echo ‘<a href=”‘.get_permalink().'” title=”‘.get_the_title().'”>’.get_the_post_thumbnail().'</a>’; … Read more

get_pages – Display child then grandchild pages

You don’t need 2 queries, just use a bit of logic and 2 foreach loops: $portfolioID = $post->ID; $portfolio_sections = array( ‘post_type’ => ‘page’, ‘child_of’ => $portfolioID, ‘sort_column’ => ‘menu_order’, ‘sort_order’ => ‘ASC’, ); $sections = get_pages($portfolio_sections); $hierachical = array(); if ( ! empty($sections) ) { foreach ( $sections as $section ) { if ( … Read more

Easy way to process search results before displaying

You can use pre_get_posts filter to filter out what you need. There’s an example on how to do this in Codex: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_Pages_from_Search_Results function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set(‘post_type’, ‘post’); } } } add_action(‘pre_get_posts’,’search_filter’); Also, this article might get you in the direction of editing the search form…

Using pagination with get_posts on page type

You should check your code because you have some sentences that will make your pagination function returns empty value. For example, the next piece of code will get you out because you are in a page template, so is_singular() returns true: if( is_singular() ) return; Also, you are using the global $wp_query object inside your … Read more

Display subpages under parent page as a list within a loop

First set your arguments(settings) $args = array( ‘post_parent’ => get_the_ID(), ‘post_type’ => ‘page’, ‘numberposts’ => -1, ‘post_status’ => ‘publish’ ); $children = get_children( $args, $output ); then you can use something like this <?php if (!empty($children)):?> <ul class=”row”> <?php foreach($children as $dest){ $permalink = get_permalink($dest->ID); echo “<li class=”col-sm-4″><a href=”https://wordpress.stackexchange.com/questions/254608/{$permalink}”>” . $dest->post_title . “</li>”; }?> </ul> … Read more