leesus.
Member
Posted 2 years ago #
I'm currently working on a site using WP as a cms and I've hit a roadblock. I'm using main parent pages to show product (child) pages as thumbnails. This works ok, the problem is I've got a special offers page that may not have child pages. I want to test if the page has children, if it does show the thumbnails as it is currently, if not display a generic "sorry we don't have anything on offer" message.
Anyone know if I can test if it the page has child pages or not (sorry, PHP isn't my strong point!)
Thanks in advance
How about using <?php $children = get_pages('child_of='.$post->ID);?>
This will list children & grandchildren. If you only want the immediate children, use <?php $children = get_pages('child_of='.$post->ID.'&parent='.$post->ID);?>
http://codex.wordpress.org/Function_Reference/get_pages
leesus.
Member
Posted 2 years ago #
Thanks esmi, I don't think thats what I'm after though.
I've already got the template to show a list with thumbnails of the page's child pages. What I need is a way of displaying a different message if there are no child pages, or listing them in the way I am currently if there are.
Example of what I mean: if ($page_has_children) { show my list as normal } else { show "no offers" text }
How could I do the $page_has_children test to then write a statement around?
Hope that makes sense!
<?php
$children = get_pages('child_of='.$post->ID);?>
if( count( $children ) != 0 ) { show list as normal }
else { show "no offers" text }
?>
abdulchalik
Member
Posted 1 year ago #
@esmi:great...thanks a lot
maark0_o
Member
Posted 1 year ago #
@esmi
Thanks, this helped me too.