Jump to content

Recommended Posts

Posted

Hi I'm an inexperienced editor, but eager to learn more about ProcessWire. I've created a simple script that echoes the bodies of a parent's children.

<?php 

foreach ($page->children as $child):
echo ("<div class='my-class'> $child->body");
endforeach;

?>
My question is how do I get these bodies to be styled individually? 
Posted (edited)

One way (and there are always many) is to have a field specifying the body class for the child in the child.

So you can Echo <class="$child->class>

(On mobile so this is tricky!)

Edited by DaveP
Posted (edited)

That field could be a text field (means you have to type it up always), a page field (single select) or an options field (probably easiest) (single select). If you don't have many child pages, you can use CSS/HTML IDs instead of classes, and do something like id=child-1, id=child-2, etc

Welcome to ProcessWire and the forums :-)

Edit: Also depending on how the children pages are named and the number you have to deal with, you could use their names for IDs...

Edited by kongondo
Posted
<?php 
foreach ($page->children as $child):
echo "<div class='my-class-$child->id'> $child->body";
endforeach;
?>

echo doesn't need (), this should also give each instance a unique class if you are looking for that :-)

  • Like 1
Posted
<?php 
foreach ($page->children as $child):
echo "<div class='my-class-$child->id'> $child->body";
endforeach;
?>

echo doesn't need (), this should also give each instance a unique class if you are looking for that :-)

Thanks Tom, that did the trick. Still a lot to learn  :)

Posted

hello, stuck again on something that is probably quite simple for experienced users. I am creating an array of images from all children of a parent that should be styled per child, so the output would be something like this:

<div class="style-1">
<img src="/site/assets/files/1016/img1.jpg>
<img src="/site/assets/files/1016/img2.jpg>
</div>

<div class="style-2">
<img src="/site/assets/files/1020/img1.jpg>
<img src="/site/assets/files/1020/img2.jpg> 
</div> 

// et cetera

So far, I've only been able to either style each individual image or style them all at once..

Posted

@Roderick,

For each new question unrelated to the original title of a thread, we start a new thread. Please start a new thread for your new question. Secondly, if a question you pose is answered to your satisfaction, please mark it as solved.

Thanks.

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
  • Recently Browsing   0 members

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