Jump to content
hollyvalero

MarkupPagerNav: So close to getting this to work... looping URLs to first page?

Recommended Posts

Trying to create a report environment for a nonprofit with a lot of lengthy guides. 3 Templates: report cover, report TOC, report pages. 

Cover will be simple http://test.hollycodes.com/a-short-history-of-flatbreads/
TOC is a list in manual order of all pages http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/

Report page is the actual report content.  These are the pages where I want pagination at the bottom in some format:  Previous   1   2  3  4   5   Next

Page numbers are turned on for the Report page template (not TOC or Cover - do they need to be on for the parent pages?)

I am trying this for pagination:

- - - - - - - 

$options = array(
  'numPageLinks' => 10,
  'listClass' => 'uk-pagination',
  'linkMarkup' => "<a href='{url}'>{out}</a>",
  'currentItemClass' => 'uk-active uk-text-bold',
  'separatorItemLabel' => '<span>…</span>',
  'separatorItemClass' => 'uk-disabled',
  'currentLinkMarkup' => '<span>{out}</span>',
  'nextItemLabel' => 'Next',
  'previousItemLabel' => 'Previous',
  'nextItemClass' => '',
  'previousItemClass' => '',
  'lastItemClass' => '',
);

$items = $page->parent->children("limit=2");
$pager = $modules->get('MarkupPagerNav');
echo $pager->render($items, $options);


 - - - - - - - 

This is giving me the active page bold, the numbers, next & previous... but all the links are relative to the current page - whichever one you are on:

http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/neanderthal-flatbreads/page2/
http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/neanderthal-flatbreads/page3/

 

Instead of going to the actual pages 

http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/neanderthal-flatbreads/
http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/indian-subcontinent/
http://test.hollycodes.com/a-short-history-of-flatbreads/table-of-contents/what-makes-flatbread-flat/

 

Been trying to suss out what I am doing wrong for a few hours and not seeing it... 

 

 

 

Share this post


Link to post
Share on other sites

all of those links are login-protected...

what's the page / tree structure look like?

Share this post


Link to post
Share on other sites
4 minutes ago, dragan said:

all of those links are login-protected...

what's the page / tree structure look like?

Oh, sorry... I took off the protected mode. It's open.

 

Top level is cover,

TOC is TOC

Pages are report pages - with the pagination...

 293157230_ScreenShot2019-01-18at2_08_17PM.thumb.png.62283df904b4bb328c334ed8c05c48ca.png

 

 

Share this post


Link to post
Share on other sites
3 hours ago, hollyvalero said:

Report page is the actual report content.  These are the pages where I want pagination at the bottom in some format

That's not how MarkupPagerNav works. The MarkupPageNav module is useful when you want to stay on one page which is listing summaries from a PageArray of other pages. The pagination is for those summaries, so if with no limit applied a selector would return a PageArray of 20 pages and you wanted to show 4 summaries per page (limit=4) on some overview page then MarkupPagerNav would create 5 links. But you always stay on the overview page - the links in the pager don't take you to the individual pages that the summaries are for.

So technically you could create a pager on the Table on Contents page, using a PageArray of child pages with a limit of 1, and then output the whole content of the child page in your foreach loop. But instead I think you want visitors to actually visit those child pages, not just stay on the Table of Contents page.

So what you want is a normal menu for the pages in your PageArray. You can create this any way that you like to create menus in your site, but here is an example:

<?php
$items = $page->siblings();
$next_page = $page->next();
$prev_page = $page->prev();
?>

<!-- Add whatever classes or extra markup you need to this unordered list -->
<?php if($items->count > 1): ?>
	<ul>
		<?php if($prev_page->id): ?>
			<li><a href="<?= $prev_page->url ?>">Previous</a></li>
		<?php endif; ?>
		<?php foreach($items as $key => $item): ?>
			<li class="<?= $page === $item ? 'current' : '' ?>"><a href="<?= $item->url ?>"><?= $key + 1 ?></a></li>
		<?php endforeach; ?>
		<?php if($next_page->id): ?>
			<li><a href="<?= $next_page->url ?>">Next</a></li>
		<?php endif; ?>
	</ul>
<?php endif; ?>

 

Edited by Robin S
Clarified about limit regarding MarkupPagerNav.
  • Like 4

Share this post


Link to post
Share on other sites
1 hour ago, Robin S said:

That's not how MarkupPagerNav works.

*** Thank you.  The more I played with it the more I thought, "you know... this is for search results...I don't think this is the right application for the pager... so I 

went on to do the next and previous page thing - less terrific than yours so I will be happy to try your code as mine is a little thin.

 

But thank you for that. Suspicions confirmed. 🙂

 

 

 

 

 

1 hour ago, Robin S said:

 


<?php
$items = $page->siblings();
$next_page = $page->next();
$prev_page = $page->prev();
?>

<!-- Add whatever classes or extra markup you need to this unordered list -->
<?php if($items->count > 1): ?>
	<ul>
		<?php if($prev_page->id): ?>
			<li><a href="<?= $prev_page->url ?>">Previous</a></li>
		<?php endif; ?>
		<?php foreach($items as $key => $item): ?>
			<li class="<?= $page === $item ? 'current' : '' ?>"><a href="<?= $item->url ?>"><?= $key + 1 ?></a></li>
		<?php endforeach; ?>
		<?php if($next_page->id): ?>
			<li><a href="<?= $next_page->url ?>">Next</a></li>
		<?php endif; ?>
	</ul>
<?php endif; ?>

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Here is a more sophisticated version if you have a large number of siblings and don't want to include all of them in the pager navigation.

<?php
// Limit for number of sibling links
$limit = 9;
// Get the number of visible siblings
$num_siblings = $page->parent->numChildren(true);
// The default start value is zero
$start = 0;
// If the number of siblings is greater than the limit then we need to adjust the start value
if($num_siblings > $limit) {
	// Get the halfway point of the limit
	$half_limit = floor($limit / 2);
	// Get the index of the current page relative to its siblings
	$index = $page->index();
	// Adjust the start value to keep the current page within the sibling links
	if($index > $half_limit) $start = $index - $half_limit;
	if($num_siblings - $start < $limit) $start = $num_siblings - $limit;
}
$items = $page->siblings("start=$start, limit=$limit");
// Next page and previous page relative to current page
$next_page = $page->next();
$prev_page = $page->prev();
?>
	
<?php if($items->count > 1): ?>
	<ul>
		<?php if($prev_page->id): ?>
			<li><a href="<?= $prev_page->url ?>">Previous</a></li>
		<?php endif; ?>
		<?php if($start > 0): ?>
			<li>&hellip;</li>
		<?php endif; ?>
		<?php foreach($items as $item): ?>
			<li class="<?= $page === $item ? 'current' : '' ?>"><a href="<?= $item->url ?>"><?= $item->index() + 1 ?></a></li>
		<?php endforeach; ?>
		<?php if($num_siblings > $start + $limit): ?>
			<li>&hellip;</li>
		<?php endif; ?>
		<?php if($next_page->id): ?>
			<li><a href="<?= $next_page->url ?>">Next</a></li>
		<?php endif; ?>
	</ul>
<?php endif; ?>

 2019-01-19_122136.png.d34405ea6b0b64cb1524ffa4f20afc58.png

  • Like 3

Share this post


Link to post
Share on other sites
2 minutes ago, Robin S said:

Here is a more sophisticated version if you have a large number of siblings and don't want to include all of them in the pager navigation.


<?php
// Limit for number of sibling links
$limit = 9;
// Get the number of visible siblings
$num_siblings = $page->parent->numChildren(true);
// The default start value is zero
$start = 0;
// If the number of siblings is greater than the limit then we need to adjust the start value
if($num_siblings > $limit) {
	// Get the halfway point of the limit
	$half_limit = floor($limit / 2);
	// Get the index of the current page relative to its siblings
	$index = $page->index();
	// Adjust the start value to keep the current page within the sibling links
	if($index > $half_limit) $start = $index - $half_limit;
	if($num_siblings - $start < $limit) $start = $num_siblings - $limit;
}
$items = $page->siblings("start=$start, limit=$limit");
// Next page and previous page relative to current page
$next_page = $page->next();
$prev_page = $page->prev();
?>
	
<?php if($items->count > 1): ?>
	<ul>
		<?php if($prev_page->id): ?>
			<li><a href="<?= $prev_page->url ?>">Previous</a></li>
		<?php endif; ?>
		<?php if($start > 0): ?>
			<li>&hellip;</li>
		<?php endif; ?>
		<?php foreach($items as $item): ?>
			<li class="<?= $page === $item ? 'current' : '' ?>"><a href="<?= $item->url ?>"><?= $item->index() + 1 ?></a></li>
		<?php endforeach; ?>
		<?php if($num_siblings > $start + $limit): ?>
			<li>&hellip;</li>
		<?php endif; ?>
		<?php if($next_page->id): ?>
			<li><a href="<?= $next_page->url ?>">Next</a></li>
		<?php endif; ?>
	</ul>
<?php endif; ?>

 2019-01-19_122136.png.d34405ea6b0b64cb1524ffa4f20afc58.png

Oooh... Even better!  I will see if I can follow along!  Thank you!!

 

h

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...