InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress How-Tos

  • angularjs in wordpress
  • Convert wordpress page to posts and vice versa
  • Find all user created wordpress custom field keys
  • How to automate wordpress sandbox setup on Linux
  • How to capture php code or included file output in a variable
  • How to check the performance of a plugin using mysql query log
  • How to migrate wordpress from root to sub directory
  • How to upgrade wordpress manually
  • How to view wordpress current version
  • Setup xdebug for remote wordpress debugging
  • Wordpress - disable theme and plugin editing
  • Wordpress - get wpdb class method names
  • Wordpress multisite network vs normal installation
  • display method names from php WP_Query object
  • find if a wordpress page is leaf page
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress How To

find if a wordpress page is leaf page

By admin on Nov 16, 2015

Sometime we want to consider pages which have children as browse pages and may treat them separately in plugins etc. For example we may not want to show related posts in them. Here is the wordpress php code you can use to find if a wordpress page is leaf page and has no child.

function _is_leaf_page($pageid) {
  $args = array(
        'sort_order' => 'asc',
        'sort_column' => 'post_title',
        'hierarchical' => 1,
        'exclude' => '',
        'include' => '',
        'meta_key' => '',
        'meta_value' => '',
        'authors' => '',
        'child_of' => $pageid,
        'parent' => -1,
        'exclude_tree' => '',
        'number' => '',
        'offset' => 0,
        'post_type' => 'page',
        'post_status' => 'publish'
  );
  $pages = get_pages($args);
  return (count($pages) == 0)? True : False;
}

And use the following code to use the above function:

  global $post;
  $post_id = $post->ID;
  $is_leaf = _is_leaf_page($post_id);

Suggested posts:

  1. How to setup MailChimp Rss email campaign
  2. How to clear Chrome HTTP 301 redirect cache
  3. How to ping feedburner to force update rss cache
  4. Fetch wordpress rss feed as FeedBurner user agent on command line
  5. How to show wordpress pages on front page with skip_home custom field
  6. How to install AWStats on Ubuntu Linux
  7. jQuery – difference between html() and text()
  8. How to create Linux instance on Amazon AWS/EC2 Classic
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Tutorials, Web Development, Wordpress, Wordpress How To
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress