Jump to content

Different rule by parent


Ollie
 Share

Recommended Posts


<?php
$item = $pages->find("template=item");
foreach($item as $item){
echo "<li><a href='{$item->url}'>";

if($item->parent = "cats"){
echo "<div id='redro'>";}
if($item->parent = "dogs"){
echo "<div id='bluero'>";}
if($item->parent = "hamsters"){
echo "<div id='greenro'>";}
else echo "<div id='roy'>";

echo "<div id='ro-info'>1/{$item->images->count()}<br />{$item->title}<br />—<br />{$item->date}</div></div>";
$image = $item->images->first();
$image = $image->width(250);
if($image) echo "<img src='$image->url'> </a></li>";
}
?>

Hi there, I am pretty new to all of this so please forgive me if i am making any sily mistakes!

I am trying to change that div id based on the items parent name, i.e if its a cat and its parent is a page called cats its a red rollover if its a dog its blue etc.

I have proberly got it very wrong up there but I have been trial and erroring for a while now and i cant seem to work it out!

Thanks in advance, Ollie

Link to comment
Share on other sites

Hi Ollie,

Without looking at your code in too much detail, the first obvious problems are the single equals signs in the if($item->parent = statements. Try using == and let us know if that fixes things.

Also, you'll probably need to do $item->parent->name

  • Like 2
Link to comment
Share on other sites

hi Adrian, thanks for your help it all seems very simple now! I am still having a small problem with it displaying the else echo on everything else 2 or 3 times depending on wether it has a parent or not, any ideas?

Thanks again!

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...