Jump to content

Pagination not working


davo
 Share

Recommended Posts

So I've followed a number of tutorials this week and combined them together making some really cool adaptions.

But, the part that I can't get to work is the simple news tutorial:

http://wiki.processwire.com/index.php/Simple_News_System

I've used the functions page as below and pagination, is the only part that I've not messed about with; but in reality, the only parts of the code i've changed is the sort order where I've asked it to be sorted by reverse natural sort order I think; this is so I get the newest news articles first.

The pagination function just seems to return the same page each time.

<?php

/* LIST ARTICLES
 
This displays a list of articles in div containers on the news-index page. 
 
 
*/
 
function newsList(){
 
	// Grab the page name from the url
 
	$thisCategory = wire("page")->name;
 
	// If the category is not called "news" then output the category name as a selector for the find.
 
	if($thisCategory !="news") {
		$category = "article_category.name=" . $thisCategory;
	}	
 
	// Get the news posts - limited to ten for later pagination
 
	$newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, sort=-sort, limit=10");
 
	$out =" ";
 
	//Loop through the pages
 
	foreach($newsposts as $newspost){
		$out .="<div class='clearfix'><hr>";
                	$out .="<BR><a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>";
		if($newspost->article_thumbnails){
			$out .="<a href='{$newspost->article_thumbnails->url}' class=''>";
			$out .="<img class='' src='{$newspost->article_thumbnails->getThumb(listingthumb)}'>";
			$out .="</a>";
		}
//		$out .="<a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>";
		$out .="<p>{$newspost->article_introtext}<a href='{$newspost->url}'> Read more...</a></p><br>";
		$out .="</div>";
 
	}
	// Pagination
 
	$out .="<div class='pagination'>";
	$out .= $newsposts->renderPager(array(
 
				    'nextItemLabel' => "Next",
				    'previousItemLabel' => "Prev",
				    'listMarkup' => "<ul>{out}</ul>",
				    'itemMarkup' => "<li>{out}</li>",
				    'linkMarkup' => "<a href='{url}'>{out}</a>"   
 
					));
	$out .="</div>";
 
	echo $out;
 
}



/* CATEGORIES LIST
 
This lists available categories
 
*/
 
function categoriesList(){
	$categories = wire("pages")->find("parent=/categories/, template=TUT_news.index, sort=title");
	$out =" ";
	foreach($categories as $category){
		$out .="<li><a href='{$category->url}'>{$category->title}</a></li>";
	}
 
	echo "<ul>$out</ul>";
 
}




/* DISPLAY ARTICLE
 
This displays the article on the news page.
 
You can change the <a> class if you are using a lightbox
*/
 
function newsDisplay(){
	$newspost = wire("page");
 
	$out =" ";
	if($newspost->article_thumbnails){
		$out .="<a href='{$newspost->article_thumbnails->url}' class=''>";
		$out .="<img class='align_right' src='{$newspost->article_thumbnails->getThumb(thumbnail)}'>";
		$out .="</a>";
	}
//	$out .="<h2>{$newspost->title}</h2>";
	$out .=$newspost->article_maintext;
 
	echo "<div class='clearfix'>$out</div>";
}





/* first attempt at newsblock
*/

function newsblock(){
 

 
	// Get the news posts - limited to ten for later pagination
 
	$blocknewsposts = wire("pages")->find("parent=/news-articles/, article_thumbnails!='',  template=TUT_news, sort=-sort, limit=12");
 
	$out =" ";
 
	//Loop through the pages
 
	foreach($blocknewsposts as $blocknewspost){
		// $out .="<div class='clearfix'>";
                
		if($blocknewspost->article_thumbnails){
			$out .="<a href='{$blocknewspost->url}' class=''>";
			$out .="<img class='' src='{$blocknewspost->article_thumbnails->getThumb(listingthumb)}'>";
			$out .="</a>";
		}
	//	$out .="</div>";
 
	}
echo $out;
}



?>

The page renders like this:

http://www.garagesalefinder.co.uk/news/

I understand most of the code, but I do get a little lost understanding the pagination code, which makes it difficult for me to debug.

I've made an image block at the end of it too which i've very please with, but the problem was there prior to that.

Link to comment
Share on other sites

Thanks Diogo

That sounded like it was going to work; I edited the template settings  and Allow Page Numbers? and I also checked Allow URL Segments?

Was this what you  meant? sadly this didn't work; any other ideas please?

Link to comment
Share on other sites

  • 1 year later...

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