Jump to content
Sign in to follow this  
melissa_boyle

IF statement if page has [3] parents

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...