Jump to content

Recommended Posts

Posted

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 } ?>

 

Posted

Got it working! Thanks!

The results are:

Quote

1 2 next

Is there a way to remove the page numbers in-between next and prev?

Posted (edited)
1 hour ago, OpenBayou said:

Is there a way to remove the page numbers in-between next and prev?

Hi, is it the same question? If so, just read the topic.

Edit: @kongondo beat me :) 

Edited by szabesz
I was too slow to reply :)
Posted
Just now, szabesz said:

Hiding them by CSS (display: none)? 

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

Posted
4 minutes ago, kongondo said:

Did u see this as well?

 

I couldn't get it to work. When I got it to work it either shows the next post or array, not page2.

Posted
Just now, OpenBayou said:

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

Sure :) But this is the easiest ;) Anyway, other options are in the thread we linked to.

Posted
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
Posted

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
Posted

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

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.
×
×
  • Create New...