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

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…

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)