Jump to content

Get last three repeater posts to another template


Roych
 Share

Recommended Posts

Hello,

I'm new to PW and like it already ;) I have just created my first site with PW and need some help getting repeater posts from one page to expl. home page.

I have a page called Events with template events.php . Page has a repeater field called Events_repeat. Now I would like to show last three events on a homepage, how do I do that.

I have tried with:

	<?php foreach ( $pages->find('template=events, limit=3') as $event ):?>
		<div class="hovereffect">
			<img src="<?=$event->images->first->url ?>" width="100%" class="img-responsive" style="border: 9px solid white;">	
			<div class="overlay">
				<h2><?= $event->images->description->first ?></h2>
			</div>
		</div>
	<? endforeach; ?>

But it doesn't work, what am I doing wrong. I tried to look on a forum but couldn't find anything helpful really.

Thank you very much ;)

R

Link to comment
Share on other sites

Hi.

In your code you find all pages with template "events", but as I understood you want to show some repeater items from "event@ page

$items = $pages->get("/event/")->events_repeater;

if($items->count()) {
	foreach($items as $items) {}
}

 

Link to comment
Share on other sites

The upper didn't quite work for me was a good starting point found this and it works great but how do I limit it to only 3 last events.

<?php
    $Events = $pages->get('/Events/')->Events_repeat->getArray();
    foreach ($Events as $key => $events) { 
	?>
<div class="col-md-4 wow animated bounceInRight">
	<div class="hovereffect">
		<img src="<?=$events->Event_slika->first->url ?>" width="100%" class="img-responsive" style="border: 9px solid white;">	
			<div class="overlay">
				<h2><?=$events->Event_slika->first->description ?></h2>
			</div>
	</div>
</div>
        
    <?php 
	if ($key == 2) {
        break;}
    };   
?>

Thank you
R

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

×
×
  • Create New...