How to Hard Set the Parent Page in Template
Just change the ‘child_of’ => $post->ID argument to ‘child_of’ => 61, or whatever the ID of the parent page is.
Just change the ‘child_of’ => $post->ID argument to ‘child_of’ => 61, or whatever the ID of the parent page is.
You need to look at get_ancestors() to get the top level parent of a page. Just a note, for reliability, use get_queried_object() (or even better $GLOBALS[‘wp_the_query’]->get_queried_object()) to get the current post/page object on singular pages, $post can be quite unreliable You can try the following in your shortcode: $post = $GLOBALS[‘wp_the_query’]->get_queried_object(); // Make sure the … Read more
Maybe array_slice($subpages, 0,5) to cut the array after 5 entries?
you can use the number param to limit the number of pages you want and get the custom field in the foreach loop 🙂 (child of = your parent page, or the current page) $mypages = get_pages( array( ‘child_of’ => $post->ID, ‘sort_column’ => ‘post_date’, ‘sort_order’ => ‘desc’, ‘number’ => 3, ) ); foreach( $mypages as … Read more
Here is the code that ended up working for me: <?php $mypages = get_pages( array( ‘child_of’ => $post->ID, ‘sort_column’ => ‘menu_order’, ‘sort_order’ => ‘asc’ ) ); foreach( $mypages as $page ) { $content = $page->post_content; $content = apply_filters( ‘the_content’, $content ); $price = get_post_meta( $page->ID, ‘price’, true ); ?> <div class=”service”> <h4><a href=”https://wordpress.stackexchange.com/questions/126795/<?php echo get_page_link( … Read more
I modified my code based on this posting’s answer, and the page displays everything I want now. <div id=”masonry-loop” class = “group”> <?php global $post; $child_pages_query_args = array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID, ); $child_pages = new WP_Query( $child_pages_query_args ); if ( $child_pages->have_posts() ) : while ( $child_pages->have_posts() ) : $child_pages->the_post(); ?> <?php $images … Read more
How to display child pages with in a limited child content?
The sort_column parameter of wp_list_pages() does allow items to be returned in random order using the rand option. 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’. add_shortcode( ‘wpb_childpages’, ‘wpb_list_child_pages’ ); function wpb_list_child_pages() { global $post; if … Read more
Looks like a syntax error to me. Try: wp_list_pages(“title_li=&child_of=2143&exclude=$current_post_id”) OR wp_list_pages(“title_li=&child_of=2143&exclude=”.$current_post_id) Also I will suggest to pass parameters as array instead of a string, for better debugging. wp_list_pages( array( ‘child_of’ => 2143, ‘exclude’ => array( $current_post_id ), ); Make sure $current_post_id is giving proper value.
I would try setting up post data in the loop and then calling a page template using get_template_part function. Note: depending on theme it may produce some unexpected results, as page template sometimes also includes site header and footer. But it’s something to get you started. $getchilds = array( ‘parent’ => $post->ID, ‘child_of’ => $post->ID, … Read more