To expand upon my comment:
Top-level page? (q.1)
global $post;
$x = get_ancestors( $post->ID, 'page' );
if( ! $x ) {
// there are no ancestors, therefore this is a top-level page
}
Childless page? (q.2)
global $post;
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
);
$x = get_children( $args );
if( ! $x ) {
// there are no children
}
References
NB — this assumes that you’re after WordPress’s page
s. If you want a different post type, replace page
in the code samples with your chose post type’s name.
Related Posts:
- A check for if is parent page, if has children, if has grandchildren
- Can I display submenus in groups, using wp_list_pages?
- Only allow new subpages to be created
- Create subpage – filter parent pages list
- How can I automatically add child pages to pages in a WP menu?
- Keep page hierarchy in wp_list_pages, even if on a child or grandchild
- Displaying direct children of other pages on homepage
- Get all children titles of a page as a link to them
- Multiple Loops That Pull Pages (Child/Grandchild) While Styling the First Entry
- Search anything from a Child and Sub-Pages of their Parent page
- Show children connected to parent pages
- how to list subpages in sidebar without widget
- Password protect page with multiple passwords
- Allow only new sub-pages to be created
- Set page template automatically based on parent
- What is the use of $page_title and how to use it?
- Some pages are missing from the Parent Page select in the Editor
- How to display code if it is not certain pages?
- Set Session Time Limit for Password Protected Posts
- Custom Search Page Pagination Not Working
- Dynamic content in a static page
- add_rewrite_rule: Issue converting path to url
- Is there a way to stop WP editor deleting
- How to change redirect after moving a page to trash?
- Static files or dynamic WP pages for “static content”?
- Add new page with preselected parent
- When I split a large post with , how can a search locate users to the correct page?
- Child page from 2 different parent pages
- Redirect “Sorry, you are not allowed to access this page.” to Home
- select a private page as parent for another private page
- Can I set a timer for pages to be published?
- Add a Menu Link (to a WordPress Page) in the Admin Menu/Sidebar
- Cannot get grandparent object
- Too Many Pages in WordPress? 2013
- How-to Change Content with location change?
- Job Manager plugin help?
- How get get list of pages in ajax search
- How to Move My Page into WordPress dashboard main menu
- List child pages by slug not ID?
- Force page to open in html mode
- Do the permalink settings apply to pages as well as posts?
- How to make tag post listing page working?
- Admin pages, edit notes of the title of posts and pages
- get_pages() & “child_of”
- How to detect if is_404() or is_page() or etc…? [closed]
- check first and last child pages wordpress
- Special Character Appearing in my WordPress Pages Content
- WordPress pages creation work distribution & then combining – Localhost XAMPP
- Prioritize visible content – Page speed issue on Google insights
- How can I check user capability when a page loads (via functions.php)?
- How can I get the blog page ID?
- Proper procedure for wp_insert_post?
- Read more on pages WordPress
- Bad pages redirection
- Parent page shows no child content
- Remove_filter (‘the_content’, ‘wpautop’) only pages
- Weebly Migration to WordPress [closed]
- Need to create a custom page on a website
- How To Render Shortcode In AJAX Response?
- Do I have to widgetize my pages?
- Use page template for custom $_GET content
- Custom page only editable by one user
- Page Title repeating
- Password Protect Pages Not Working
- Can I connect a page to a taxonomy?
- wp_nav_menu: output featured image of each page listing
- Is there a template tag/function for getting the URL (or slug or name or ID) of the blog page when using a “static” front page
- Prompting for review / reapproval of page content
- Limit the amount of main pages
- Change displayed “page name” to distinguish multiple pages with the same title
- add title to widgets of wordpress
- Custom user tables not working after migration
- remove “Edit” from select pages
- How to transfer a site to hosting?
- Add the same content to multiple pages
- How can a .css file be applied to a virtual page?
- WordPress blog posts template bug [closed]
- Checkboxes to automatically create pages when I activate a theme
- Share a folder with files
- Front Page post mirroring revisions to other pages, constantly updating itself
- Microsoft Security Essentials is blocking my WordPress website in IE11
- Cannot use old slug – it just 301s to site home page
- Author information on all pages
- Display inner pages like posts.[Like how post excerpt works]
- include exception inside theme for empty widget area
- My pages disappeared from the list
- How to display time when page is created and edited
- Auto-Create Pages from Template Directory
- different single.php for different page templates
- Passing variables through a href link from one page to another page
- displaying child pages in columns when on a parent page
- page wordpress add extra unwanted stuff
- How to align bold,italic and underline in wp-admin?
- Parent – Child Pages and Templating in wordpress
- How to remove the trackback and pingback text on the bottom of my pages?
- Output the published date / last modified date of specific page
- Create a plugin to create a new page in wordpress for each time a record is added into the database
- Query page: preserve page formating
- How to remove container box in WordPress pages? [closed]
- Fresh WordPress installation not able to simply show page content