tooth-paste

Display recent items repeater

Recommended Posts

I'm trying to build a calendar from a repeater field. One of the field is the date of an event. Is it possible to only display the items for today and later? Can I hide older items?

1343192784_Schermafbeelding2018-06-27om22_10_09.thumb.png.b08455f5f4f27eaf3fc0b370d4cc94a3.png

Code:

foreach($page->agendaitem as $item) {
	echo "<h4>{$item->activiteit}</h4><p>
	<b>{$item->datum} {$item->tijd}</b><br />
	{$item->beschrijving} </p>
	<div class='stippellijnzwart'></div>";
}   
							

 

Share this post


Link to post
Share on other sites

Honestly... go with pages for each event. It's much easier to handle and much easier to [everything].

Repeaters are nice but events/dates/calendar entries are more than just an item in a page.

If you used pages instead of repeaters you could use:

<?php
$eventsToday = $pages->find("template=event, date=today");
?>

Just create a root element, for example: page with template events, for all your events and place all evens underneath it.

  • Like 1

Share this post


Link to post
Share on other sites

@wbmnfktr Repeater items are actually pages too.

@tooth-paste Here is how you can do it:

<?php if(count($page->event_repeater)) {
  $today = strtotime("today");
  $upcoming_dates = $page->event_repeater->find("event_date>=$today, sort=event_date");

  if(count($upcoming_dates)) {
    
    foreach($upcoming_dates as $upcoming_date) {

?>

<div>...</div>

<?php } 
  } 
} ?>

 

  • Like 2

Share this post


Link to post
Share on other sites
6 minutes ago, PWaddict said:

Repeater items are actually pages too.

I totally agree with that but pages in pages under pages (repeaters) is something different. So plain pages are always more easily to control.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, wbmnfktr said:

I totally agree with that but pages in pages under pages (repeaters) is something different. So plain pages are always more easily to control.

I think it depends on the content.

Share this post


Link to post
Share on other sites
6 hours ago, PWaddict said:

@wbmnfktr Repeater items are actually pages too.

@tooth-paste Here is how you can do it:


<?php if(count($page->event_repeater)) {
  $today = strtotime("today");
  $upcoming_dates = $page->event_repeater->find("event_date>=$today, sort=event_date");

  if(count($upcoming_dates)) {
    
    foreach($upcoming_dates as $upcoming_date) {

?>

<div>...</div>

<?php } 
  } 
} ?>

 

Thx! works perfect!

Share this post


Link to post
Share on other sites

Can I place the code on another page (like homepage, recent three)?

if(count($page->agendaitem)) {
							$today = strtotime("today");
							$upcoming_dates = $page->agendaitem->find("agenda_datum>=$today, sort=agenda_datum");
						
								if(count($upcoming_dates)) {
						    
									foreach($upcoming_dates as $upcoming_date) {
						
										echo "<h4>{$upcoming_date->agenda_activiteit}</h4><p>
										<b>{$upcoming_date->agenda_datum} {$upcoming_date->agenda_tijd}</b><br />
										{$upcoming_date->agenda_beschrijving} </p>
										<div class='stippellijnzwart'></div>";						
									} 
								} 
						} 

 

Share this post


Link to post
Share on other sites

@tooth-paste Of course just add a limit on your selector like this:

$upcoming_dates = $page->agendaitem->find("agenda_datum>=$today, sort=agenda_datum, limit=3");

 

Share this post


Link to post
Share on other sites

@PWaddict: Thank you, but can I place the code on a different page(homepage)? I tried the following code but it does not work. I added 'get'

$upcoming_dates = $pages->get("/agenda")->agendaitem->find("agenda_datum>=$today, sort=agenda_datum, limit=3");

 

Share this post


Link to post
Share on other sites
10 minutes ago, tooth-paste said:

@PWaddict: Thank you, but can I place the code on a different page(homepage)? I tried the following code but it does not work.

 

Sorry my mistake. The selector code if placed on another page must be $pages->find. Try this:

$upcoming_dates = $pages->find("template=your_event_template, agenda_datum>=$today, sort=agenda_datum, limit=3");

 

Share this post


Link to post
Share on other sites

This line doesn't work. Could it have to do with the repeater 'agendaitem'?

$upcoming_dates = $pages->agendaitem->find("template=agenda, agenda_datum>=$today, sort=agenda_datum, limit=3");

 

Share this post


Link to post
Share on other sites

Try the below but on the template enter the name of the repeater template. If you go to "Setup > Templates > Filters > Show system templates? > Yes" you'll find that your repeater field has a template like this: repeater_your_event_repeater:

$upcoming_dates = $pages->find("template=repeater_your_event_repeater, agenda_datum>=$today, sort=agenda_datum, limit=3");

 

Share this post


Link to post
Share on other sites

I've never output repeater content outside from their pages so maybe I'm not the right guy to help you. Until someone else can reply you should check the Repeater demonstration page on the part "Finding pages by repeater value (using selectors)".

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.