Jump to content

Display recent items repeater


tooth-paste
 Share

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>";
}   
							

 

Link to comment
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
Link to comment
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
Link to comment
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!

Link to comment
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>";						
									} 
								} 
						} 

 

Link to comment
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");

 

Link to comment
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");

 

Link to comment
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");

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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