Jump to content
Roych

List (table) of all posts, by page reference field values?

Recommended Posts

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

prtscr-table.thumb.jpg.36d5ac47546203124f20e2d94b82ce6e.jpg

I just hope you understand what I mean ūüėČ

Thank you very much in advance

R

Share this post


Link to post
Share on other sites

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 } ?>
		

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, 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 } ?>

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

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

√ó
√ó
  • Create New...