Jump to content

Recommended Posts

Posted

I'm implementing a news section on a site I'm developing and I'd like to add pagination for when there are a large number of news items. I've enabled pagination on the templates used and added the code to output it, limiting it to 10 items per page. However, on a page with only 4 items it's showing pagination links for a page 2. The links themselves don't click through, and if I manually try to get to page 2 I get a page missing error. I should note that the links generated don't click through on any pages where they're generated, even if there are more than the 10 item limit. 

Posted
//setup variables and content
	$newslist ='';
	$children = $pages->get("template=news")->children("limit=10, template=news_item, category.title=education, sort=-date, include=hidden");
	$pagination = $children->renderPager();
	$x ='';
	
	foreach ($children as $child){
		$x++;
			if($x == 1){
				//populate $newslist
			}else{
				//do something else
			}
	}
									
// output content								
if($sidebar){
	$copy.='<div class="row">
		<div class="small-12 medium-9 medium-push-3 columns">
			<div class="row">
				<h2 class="">'.$title.'</h2>
				
				<div class="row">
					<div class="small-12 columns padded-bottom">'
						.$pagination.
					'</div>
				</div>
					
				<div class="row">
					<div class="small-12 columns">
						'.$newslist.'
					</div>
				</div>
	
				<div class="row">
					<div class="small-12 columns padded-bottom">'
						.$pagination.
					'</div>
				</div>
			</div>
		</div>
				
		<div class="small-12 medium-3 medium-pull-9 columns">
			<div id="sidebar" class="clipped-b">
				'.$sidebar.'
			</div>
		</div>				
	</div>';
}else{
	//do something else
}

The offending section of code is above. I've spent the last hour or so re-writing the template and now I get the correct number of items and the correct number of links, but I still can't click on the links. Hovering over the link it previews the correct links, they just will not click.

1 hour ago, SamC said:

@houseofdeadleg(your work is very impressive btw, I enjoyed looking through the illustrations)

 

Thanks very much:)

Posted

Sorry, but I use a different approach to templating and I find the above pretty confusing. I think another member will have to chime in here because I don't really understand the delayed output approach.

That said, links that display but don't click sounds like a typo in the html/css. Is a row (invisibly) covering the buttons or something?

Maybe double check the actual html output in the developer tools.

Posted

Yeah, already checked all that, all the output is fine, nothing over the top that's getting in the way. The link previews, the cursor changes on hover, just won't click through.

Posted
2 hours ago, houseofdeadleg said:

$pages->get("template=news")->children("limit=10, template=news_item, category.title=education, sort=-date, include=hidden");

Try to replace "get" with "find" .. 

get("template=news") =====>  find("template=news")

Posted

There's something strange going on. If I remove all css that affects the links they still don't work if I try to click on them, however they open fine if I right click and open them in a new window/tab.

If I use ghost css for example, they work straight away, on click and right-click.

Posted
3 hours ago, houseofdeadleg said:

$x ='';

foreach ($children as $child) {

$x++;

If $x is a counter var, shouldn't it be 

$x = 0; // instead of empty string?

?

  • Like 1
Posted

What happens if you just render it like in the PW docs example?

<?php
$results = $pages->get("template=news")->children("limit=10, template=news_item, category.title=education, sort=-date, include=hidden");
$pagination = $results->renderPager();
echo "<ul>";
foreach($results as $result) {
    echo "<li><a href='{$result->url}'>{$result->title}</a></li>";
}
echo "</ul>";
echo $pagination;

 

Posted

@houseofdeadleg weird! I'm pretty intrigued with this. Gonna go try pagination right now on my test site.

=EDIT=

Ok, just did it and works ok.

<?php namespace ProcessWire; ?>

<?php
// template file blog-index.php
// make sure to set pagination on the template that lists the pages,
// not on the template of the individual items that are being listed
// i.e. in your case, on template 'news'
?>

<?php
  // get top level posts only under /tutorials/
  $entries = $pages->find("template=blog-entry|complete-guide, sort=-postDate, parent=1017, limit=6");
  $pagination = $entries->renderPager();
?>

<div class="container py-5">
  <?= $pagination; ?>
</div>

<div class="container py-5">
  <div class="row">

  <?php foreach ($entries as $entry): ?>

    <div class="col-md-4 mb-5">
      <?php include("./includes/card" . ".php"); ?>
    </div>

  <?php endforeach; ?>

  </div>
</div>

...outputs:

<ul class='MarkupPagerNav' role='navigation' aria-label='Pagination links'>
  <li aria-label='Page 1, current page' class='MarkupPagerNavOn MarkupPagerNavFirst MarkupPagerNavFirstNum' aria-current='true'><a href='/processwire-tutorials/'><span>1</span></a></li>
  <li aria-label='Page 2'><a href='/processwire-tutorials/page2/'><span>2</span></a></li>
  <li aria-label='Page 3' class='MarkupPagerNavLastNum'><a href='/processwire-tutorials/page3/'><span>3</span></a></li>
  <li aria-label='Next page' class='MarkupPagerNavNext MarkupPagerNavLast'><a href='/processwire-tutorials/page2/'><span>Next</span></a></li>
</ul>

And on screen, just a basic list:

59ea2ea109d6e_ScreenShot2017-10-20at18_12_22.thumb.png.c89b3d7acf5e76cf06742eceead12541.png

Pretty confused at why yours don't click.

 

  • Like 1

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