Roderick Posted December 12, 2015 Share Posted December 12, 2015 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? Link to comment Share on other sites More sharing options...
DaveP Posted December 12, 2015 Share Posted December 12, 2015 (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 December 12, 2015 by DaveP Link to comment Share on other sites More sharing options...
kongondo Posted December 12, 2015 Share Posted December 12, 2015 (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 December 12, 2015 by kongondo Link to comment Share on other sites More sharing options...
DaveP Posted December 12, 2015 Share Posted December 12, 2015 Yeh, what @kongondo said. Link to comment Share on other sites More sharing options...
Tom. Posted December 13, 2015 Share Posted December 13, 2015 <?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 1 Link to comment Share on other sites More sharing options...
Roderick Posted December 13, 2015 Author Share Posted December 13, 2015 <?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 Link to comment Share on other sites More sharing options...
Roderick Posted December 13, 2015 Author Share Posted December 13, 2015 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.. Link to comment Share on other sites More sharing options...
kongondo Posted December 13, 2015 Share Posted December 13, 2015 @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. Link to comment Share on other sites More sharing options...
Roderick Posted December 13, 2015 Author Share Posted December 13, 2015 @kongondo sorry, yes. Will do. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now