Jump to content

$pages->count doesn't count?


ndolph
 Share

Recommended Posts

So, I've got this really really simple function in functions.php

function dopagination()
{
	$numofpages = $pages->count("has_parent=/posts/");
	return $numofpages;
}

And then I have this in pagination.inc

<div class="row">
	<div class="col-md-12">
		<?php
		$pagination = dopagination();
		echo $pagination;
		?>
	</div>
</div>

And it pukes this at me...


Error: Call to a member function count() on a non-object (line 23 of /var/www/de.net/dev/site/templates/functions.php)
This error message was shown because you are logged in as a Superuser. Error has been logged.

Uhm, am I doing something really wrong?

Link to comment
Share on other sites

Whether or not you change your mind, the issue you had is actually well explained in that puke you mentioned: you're trying to use method count() of something that isn't an object, and thus can't have its own methods. This non-object in your case is the $pages, used in a function.

The reason for this is that in functions and class methods you have to use API vars with the wire() function -- wire('page'), wire('pages'), wire('session'), etc. In other words, your code should work just fine if you just replace $pages with wire('pages') :)

You're right in that ProcessWire has built-in pagination support: https://processwire.com/api/modules/markup-pager-nav/.

  • Like 3
Link to comment
Share on other sites

Whether or not you change your mind, the issue you had is actually well explained in that puke you mentioned: you're trying to use method count() of something that isn't an object, and thus can't have its own methods. This non-object in your case is the $pages, used in a function.

The reason for this is that in functions and classes you have to use API vars with the wire() function -- wire('page'), wire('pages'), wire('session'), etc. In other words, your code should work just fine if you just replace $pages with wire('pages') :)

You're right in that ProcessWire has built-in pagination support: https://processwire.com/api/modules/markup-pager-nav/.

Ah I figured this as it works inside of another file that is included different etc...

The built-in pagination support doesn't make sense to me :( and how I'm trying to impliment it honestly...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...