Jump to content


Photo

Pagination issues

solved pagination urlsegment

  • Please log in to reply
2 replies to this topic

#1 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 788 posts
  • 205

  • LocationMidlands, UK

Posted 04 May 2012 - 12:08 PM

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:&nbsp;&nbsp;</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>&nbsp;&nbsp;/&nbsp;&nbsp;</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; ?> &nbsp;by&nbsp; <?php echo $entry->createdUser->first_name . "&nbsp;" . $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:&nbsp;&nbsp;</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>&nbsp;&nbsp;/&nbsp;&nbsp;</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; ?> &nbsp;by&nbsp; <?php echo $entry->createdUser->first_name . "&nbsp;" . $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, 12 May 2012 - 02:22 PM.


#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,753 posts
  • 3102

  • LocationAtlanta, GA

Posted 04 May 2012 - 01:53 PM

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.

#3 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 788 posts
  • 205

  • LocationMidlands, UK

Posted 05 May 2012 - 04:38 AM

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.





Also tagged with one or more of these keywords: solved, pagination, urlsegment

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users