<?php
	snippet('header');
	snippet('rightlogoheader');

	$articlesPerPage = 3;

	foreach($articles = $page->children()->listed()->flip()->paginate(3) as $article):
		$newsImage = $article->images()->template('newsimage');
		if ($newsImage) $newsImage = $newsImage->first();
?>

	<article class="news">
	<h5><a href="<?= $article->url() ?>"><?= $article->title()->html() ?></a></h5>
		<?php if ($newsImage) { ?>
			<img src="<?= $newsImage->resize(100, 100)->url() ?>" class="imageright"/>
		<?php } ?>
		<p class="newspublished">Published: <span class="newsdate"><?= $article->date()->toDate('d-M-Y') ?></span></p>
		<p><?= $article->text()->excerpt(150) ?></p>
		<a href="<?= $article->url() ?>">Read more...</a>
	</article>

<?php endforeach; ?>

<?php $pagination = $articles->pagination() ?>

	<nav aria-label="News Navigation">
		<ul class="pagination justify-content-center">
			<li class="page-item">
				<?php if ($pagination->hasPrevPage()): ?>
					<a class="page-link" href="<?= $pagination->prevPageURL() ?>" aria-label="Previous">
						<span aria-hidden="true">&laquo;</span>
					</a>
				<?php else: ?>
					<span class="page-link" aria-hidden="true">&laquo;</span>
				<?php endif ?>
			</li>

			<?php foreach ($pagination->range(10) as $r): ?>
				<?php if ($pagination->page() === $r): ?>
					<li class="page-item active" aria-current="page">
						<span class="page-link"><?= $r ?></span>
					</li>
				<?php else: ?>
					<li class="page-item"><a class="page-link" href="<?= $pagination->pageURL($r) ?>"><?= $r ?></a></li>
				<?php endif ?>
			<?php endforeach ?>

			<li class="page-item">
					<?php if ($pagination->hasNextPage()): ?>
						<a class="page-link" href="<?= $pagination->nextPageURL() ?>" aria-label="Next">
							<span aria-hidden="true">&raquo;</span>
						</a>
				<?php else: ?>
					<span class="page-link" aria-hidden="true">&raquo;</span>
				<?php endif ?>
			</li>
		</ul>
	</nav>

<?php
	snippet('rightlogofooter');
	snippet('footer');
?>
