Jump to content

IF statement if page has [3] parents


melissa_boyle
 Share

Recommended Posts

Hi Guys,

I am trying to create an IF statement that will show text only if the parent exists.

I have made a start to but when the page does have the third parent as such it still shows the else statement.

Can anyone help please?

$parents = $resort->parents;
  echo $parents[2]->title;
 
if ($resort->has_parent[3]) {
  echo ", ";
echo $parents[3]->title;
}
 
else {
echo "test";
}
 

Thanks in advance,

Mel

Link to comment
Share on other sites

Not really sure what you are trying to do, since you don't have to check if a parent exists. A parent always exists in ProcessWire. This is how you can check the number of parents. Maybe that will help you out.

$parentCount = count($page->parents);
if ($parentCount == 2) echo "do something";
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...