Jump to content

How to do pages on a theme?


OpenBayou
 Share

Recommended Posts

Hello,

How do you do pages on a template? For example, I want my template to show only 5 posts. If there's more, do page=2. Search results I found results in errors on my end.

// posts from the parent page. Only show 5 posts
<?php foreach($pages->find("parent=recommendations,limit=5") as $child) { ?>


            <?php echo $child->title;?><br />


        <?php } ?>

 

Link to comment
Share on other sites

41 minutes ago, OpenBayou said:

It's not really good practice because it still loads the data and your browser is hiding it.

I don't think you should worry about those extra characters in the markup.

  • Like 1
Link to comment
Share on other sites

Thanks everyone. Got it working but don't like how complex it is to do next page and previous page while other CMSs have an easy option.

<?php $total_pages = ceil($pagedata->getTotal() / $limit);?>


		<?php if($total_pages > 1): $current_url = $page->url; if($input->urlSegmentsStr) $current_url .= $input->urlSegmentsStr . '/'; ?>
		  <div class="pagination">
		      <?php if($input->pageNum > 2): ?>
						<div class="prev-page">
							<a rel="prev" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum - 1) ?>">Prev page</a>
						</div>
		      <?php elseif($input->pageNum === 2): ?>
						<div class="prev-page">
							<a rel="prev" href="<?= $current_url ?>">Prev page</a>
						</div>
		      <?php else: ?>
		      <?php endif; ?>
		      <?php if($input->pageNum < $total_pages): ?>
						<div class="next-page">
							<a rel="next" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum + 1) ?>">Next page</a>
						</div>
		      <?php else: ?>
		      <?php endif; ?>
		  </div>
		<?php endif; ?>

 

  • Like 1
Link to comment
Share on other sites

It's as complex as building such things on your own elsewhere. We have an easy pagination generating module, which just happens to lack an option to render just next/prev links instead of a full pagination. I'm sure Ryan could add those quite easily.

Also may I suggest a more readable version of yours. Things are always easier to digest when they're not muddled with html tags.

<?php
	$next = $prev = '';
	$total_pages = ceil($pagedata->getTotal() / $limit);

	if($input->pageNum > $total_pages) // Optional; For page 11 of 10
		throw new Wire404Exception();

	if($total_pages > 1){
		$base_url = rtrim($page->url . $input->urlSegmentsStr, '/') . '/';

		if($input->pageNum == 2)
			$prev = $base_url;
		elseif($input->pageNum > 2)
			$prev = $base_url . $config->pageNumUrlPrefix . ($input->pageNum - 1);
      
		if($input->pageNum < $total_pages)
			$next = $base_url . $config->pageNumUrlPrefix . ($input->pageNum + 1);
	} 
?>
<?php if($next || $prev) : ?>
<div class="pagination">
		<?php if($prev): ?>
			<div class="prev-page">
				<a rel="prev" href="<?= $prev ?>">Prev page</a>
			</div>
		<?php endif; if($next): ?>
			<div class="next-page">
				<a rel="next" href="<?= $next ?>">Next page</a>
			</div>
		<?php endif; ?>
</div>
<?php endif; ?>

 

  • Like 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...