Roych Posted April 7, 2021 Share Posted April 7, 2021 Hello, Not sure if my title is appropriate for this post but I don't know how to explain in short what I need. ? So I want to create a table of all posts and show what page reference field value is asigned to each post. Visualy I need something like this: # | EDIT | PUBLISHED | POST TITLE | first PageReference SPORT | second PageReference COOKING | third PageReference HEALTH | ... | ... 1 | edit | yes | my post 1 | yes | yes | / | ... | ... 2 | edit | yes | my post 2 | / | yes | yes | ... | ... 3 | edit | no | my post 3 | yes | yes | yes | ... | ... I hope you get the idea. So I have tried to create this but somehow not working as expected. My code below: Atm I'm showing values instead of Yes & No, just to see if it works. <table class="table table-bordered table-hover"> <thead> <tr> <th scope="col">#</th> <th scope="col">edit</th> <th scope="col">published</th> <th scope="col">Article title</th> <?php foreach($pages->get(1067)->children() as $child) { echo "<th scope='col'><a href='{$child->url}'>{$child->title}</a></th>"; } ?> </tr> </thead> <tbody> <?php foreach ( $pages->find('template=blog-detail, sort=-created, include=all') as $single ):?> <tr> <th scope="row"></th> <?php if($user->isLoggedin()){ if($single->editable()) { // if editable by user. echo "<td><a class='editpage-inline' href='https://" . $config->urls->httpHost . $config->urls->admin . "page/edit/?id=". $single->id ."&modal=1'> <i class='fa fa-pencil' aria-hidden='true'></i> Uredi!</a></td> "; }};?> <?php if($single->is(Page::statusUnpublished)): ?> <td style="color:red;font-weight:800;">Ne</td><?php else:?><td>Da</td> <?php endif; ?> <td><a href="<?= $single->url ?>" target="_blank"><?=$single->title;?></a></td> <?php if($single->zasvojenosti_select) :?> <?php foreach($single->zasvojenosti_select as $item):?> <td><?=$item->title?></td> <?php endforeach; ?> <?php else:?> <td>no</td> <?php endif;?> </tr> <?php endforeach; ?> </tbody> </table> It is working somehow but it is all messed up. The columns are not showing up as they should, there should be an empty column if the value is not set for the article. This is what I get I just hope you understand what I mean ? Thank you very much in advance R Link to comment Share on other sites More sharing options...
BitPoet Posted April 7, 2021 Share Posted April 7, 2021 When you iterate over $single->zasvojenosti_select, you only get those page references that are select. You need to iterate over the possible choices like you do in the header instead. <?php foreach($pages->get(1067)->children() as $child) { if($single->zasvojenosti_select->has($child)): ?> <td>Yes</td> <?php else:?> <td>no</td> <?php endif;?> <?php } ?> 1 Link to comment Share on other sites More sharing options...
Roych Posted April 7, 2021 Author Share Posted April 7, 2021 On 4/7/2021 at 12:30 PM, BitPoet said: <?php foreach($pages->get(1067)->children() as $child) { if($single->zasvojenosti_select->has($child)): ?> <td>Yes</td> <?php else:?> <td>no</td> <?php endif;?> <?php } ?> Expand yes, it is working perfectly now! ? I actualy already tried that but I guess i did something wrong because I couldn't make it work. Thank you very much ? R 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