Check if post has children or not

You can first attempt and get a list of post’s children. If the returned value was empty, then the post has no child. Here’s how you do it: $args = array( ‘post_parent’ => get_the_ID(), // Current post’s ID ); $children = get_children( $args ); // Check if the post has any child if ( ! … Read more

Prev/Next child navigation for current page?

All right, here it is, fully working: <?php $pagelist = get_pages(“child_of=”.$post->post_parent.”&parent=”.$post->post_parent.”&sort_column=menu_order&sort_order=asc”); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; ?> <div class=”navigation”> <?php if (!empty($prevID)) { ?> <div class=”previous”> <a href=”https://wordpress.stackexchange.com/questions/54422/<?php echo get_permalink($prevID); ?>” title=”<?php echo get_the_title($prevID); ?>”>Previous</a> </div> <?php } … Read more

Show just one level of child pages, wp_list_pages woe

This should work, using nothing more than the available argument-array parameters for wp_list_pages(): specifically, depth and child_of. To display one level of hierarchy, for descendant pages of the current page: <?php // Globalize the $post variable; // probably already available in this context, but just in case… global $post; wp_list_pages( array( // Only pages that … Read more

How to make child categories recognize parent’s template displays

Thanks to @Rarst for guiding me to the right direction. Using his direction I googled again and again and found a blog article of WerdsWords with an excellent bit of code snippet filtered to category_template as Rarst suggested me, and the good news is: it worked for my cause: function new_subcategory_hierarchy() { $category = get_queried_object(); … Read more

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

Check if a post is in any child category of a parent category

Add the following to your theme’s functions.php: /** * Tests if any of a post’s assigned categories are descendants of target categories * * @param int|array $cats The target categories. Integer ID or array of integer IDs * @param int|object $_post The post. Omit to test the current post in the Loop or main query … Read more

Custom Nav walker display current menu item children, or siblings on no children

This is the walker I used to display only children of the current menu item. Or the menu items siblings if it doesn’t have any children of its own. There are comments throughout the class explaining each section <?php class SH_Child_Only_Walker extends Walker_Nav_Menu { private $ID; private $depth; private $classes = array(); private $child_count = … Read more