Jump to content

Pagination issues


onjegolders
 Share

Recommended Posts

Hi guys, have been having an issue with pagination. It's a bit odd,

I have it working fine as per Ryan's docs but when I get to a page2 of results, my categories don't display. I should add that my categories are generated at the top of the page in their own loop.

The template also uses urlSegment to filter the results by category. I have added pagination to both the news template and also the categories template which get's called through urlSegment.

On the main news page, pagination works but the categories come up empty when on the 2nd page.

On the categories template, the pagination won't show at all, and I'm not sure why as it's pretty much an identical setup to the news template.

Here's all the code, in case any of you can make sense of it.... Thanks.

News index :

<?php include("./header.inc"); ?>

<div id="news_index" class="grey_gradient">

<?php if ($input->urlSegment1 !="") {
include ("./categories.php");
} else { ?>

<div id="news_top_bar">

<h5 id="news_header">Recent news items</h5>

<?php $news_cats = $pages->find("template=news_category");
if ($news_cats) { ?>

<ul id="news_cats">
<li>By category:  </li>
<?php foreach ($news_cats as $cat) {
$numArticles = $pages->count("template=news_entry, news_category_link=$cat");
if ($numArticles > 0) {
?>
<li><a href="<?php echo $page->url  . $cat->name; ?>"><?php echo $cat->title; ?></a>  /  </li>
<?php } ?>
<?php } ?>
</ul>

<?php } ?>

<div class="clear"></div><!-- /.clear -->

</div><!-- /#news_top_bar -->

<?php $news = $page->children("sort=-created, limit=3");

foreach ($news as $entry) {

$class = "news_box";

if ($entry == $news->last()) { $class .= " news_box_last"; } ?>

<div class="<?php echo $class; ?>">

<div class="news_index_text">

<h3><a href="<?php echo $entry->url; ?>"><?php echo $entry->title; ?></a></h3>
<h6><?php echo $entry->entry_date; ?>  by  <?php echo $entry->createdUser->first_name . " " . $entry->createdUser->last_name; ?></h6>

<?php if ($entry->summary) {

echo "<p>" . $entry->summary . "</p>";

} else {

$body_text = strip_tags($entry->body);
$text = substr($body_text, 0, 300);
echo "<p>$text...</p>";
} ?>

<a href="<?php echo $entry->url; ?>" class="button">Read on</a>

</div><!-- /.news_index_text -->

<?php if ($entry->main_image) {

$news_image = $entry->main_image->size(240,180); ?>

<img src="<?php echo $news_image->url; ?>" width="<?php echo $news_image->width; ?>" height="<?php echo $news_image->height; ?>" alt="<?php echo $entry->title; ?>" class="small_frame" />

<?php } ?>

<div class="clear"></div><!-- /.clear -->

</div><!-- /.news_box -->

<?php }
?>

<?php // PAGINATION LINKS
$pagination = $news->renderPager();
echo $pagination;
?>

<?php } ?>

</div><!-- /#news_index -->

<?php include("./footer.inc"); ?>

Categories.php :

<?php
$name = $sanitizer->pageName($input->urlSegment1);
$category = $pages->find("template=news_category, name=$name");
$news_cats = $pages->find("template=news_category");
?>

<div id="news_top_bar">

<h5 id="news_header">Recent news items - <?php echo ucwords($name); ?></h5>

<?php if ($news_cats) { ?>

<ul id="news_cats">
<li>By category:  </li>
<?php foreach ($news_cats as $cat) {
$numArticles = $pages->count("template=news_entry, news_category_link=$cat");
if ($numArticles > 0) {
?>
<li><a href="<?php echo $page->url  . $cat->name; ?>"><?php echo $cat->title; ?></a>  /  </li>
<?php } ?>
<?php } ?>
</ul>

<?php } ?>

<div class="clear"></div><!-- /.clear -->

</div><!-- /#news_top_bar -->

<?php $news = $pages->find("template=news_entry, news_category_link=$category, limit=1");

foreach ($news as $entry) {

$class = "news_box";

if ($entry == $news->last()) { $class .= " news_box_last"; } ?>

<div class="<?php echo $class; ?>">

<div class="news_index_text">

<h3><a href="<?php echo $entry->url; ?>"><?php echo $entry->title; ?></a></h3>
<h6><?php echo $entry->entry_date; ?>  by  <?php echo $entry->createdUser->first_name . " " . $entry->createdUser->last_name; ?></h6>

<?php if ($entry->summary) {

echo "<p>" . $entry->summary . "</p>";

} else {

$body_text = strip_tags($entry->body);
$text = substr($body_text, 0, 300);
echo "<p>$text...</p>";
} ?>

<a href="<?php echo $entry->url; ?>" class="button">Read on</a>

</div><!-- /.news_index_text -->

<?php if ($entry->main_image) {

$news_image = $entry->main_image->size(240,180); ?>

<img src="<?php echo $news_image->url; ?>" width="<?php echo $news_image->width; ?>" height="<?php echo $news_image->height; ?>" alt="<?php echo $entry->title; ?>" class="small_frame" />

<?php } ?>

<div class="clear"></div><!-- /.clear -->

</div><!-- /.news_box -->

<?php }
?>

<?php // PAGINATION LINKS
$pagination = $news->renderPager();
echo $pagination;
?>

I've just re-read part of the pagination docs here and have added "start=0, limit=n" to my news_index template so now categories are showing even on 2nd page. Still can't seem to get pagination showing on categories template though

Edited by Soma
Link to comment
Share on other sites

Glad you figured out the start=0 thing for the news_index. When you are using pagination, PW will attempt to paginate all of your find() or children() function calls that have any limit=something. So adding start=0 is the way to keep them in check.

For the categories template, the only "limit=" statement that I see says "limit=1". In order for pagination to be activated, there has to be a limit greater than 1. You may be able to get the result you want by doing a $pages->find("limit=2, start=" . ($input->pageNum-1)); and then just using the first page it returns.

Link to comment
Share on other sites

Hi Ryan, thanks for the help I seem to have it working now, the limit=1 was just to try and start off pagination as a test because I only had 2 articles for any given category, but have now upped that and all seems well.

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

×
×
  • Create New...