ndolph Posted December 11, 2014 Share Posted December 11, 2014 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 More sharing options...
ndolph Posted December 11, 2014 Author Share Posted December 11, 2014 Eh, changed my mind on the approach I guess.... I thought PW had built in pagination? Probably not for what I want to do though or how I'm doing things. Link to comment Share on other sites More sharing options...
teppo Posted December 11, 2014 Share Posted December 11, 2014 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/. 3 Link to comment Share on other sites More sharing options...
ndolph Posted December 11, 2014 Author Share Posted December 11, 2014 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 More sharing options...
kixe Posted December 11, 2014 Share Posted December 11, 2014 In your function you are just asking for the total number. If you need only this thats easy done. $pages->get('name=posts')->numChildren; more optionshttp://cheatsheet.processwire.com/page/built-in-fields-reference/page-numchildren/ 3 Link to comment Share on other sites More sharing options...
kongondo Posted December 11, 2014 Share Posted December 11, 2014 ...yes, and it's faster than count() https://processwire.com/talk/topic/3094-get-first-image-and-title-of-children-pages/?p=30470 https://processwire.com/talk/topic/3094-get-first-image-and-title-of-children-pages/?p=30608 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now