Prev and Next
Permalink
I have a bunch of sub nav pages for "products" in c5 to display 1 product per page. is there a javascript to go to the next page (product) in the same nav level for prev and next buttons?
I hope that makes sense...
I hope that makes sense...
Yea a block for something like that would be great! Would it be hard to make? I'm starting to try and make my own blocks. Entry level obviously but if something like this isn't too hard it might be a good one to start with.
give it a try
I'm getting a Fatal error: Call to a member function getCollectionPath() on a non-object
on this line...
$nextCollectionURL=$nextCollection->getCollectionPath();
any ideas?
on this line...
$nextCollectionURL=$nextCollection->getCollectionPath();
any ideas?
that code I posted was intended to work with a page type and a page type controller. if you're trying to set it up as a block, it'll take some modifications.
I'm trying to use the page type and the page type controller. I'm getting that error on the page type. which would be my left_sidebar.php in my theme correct?
maybe there isn't a sibling page there yet? You should just test that you've got a valid collection object before you run that method on it.
I don't think I'm advanced enough for it. Are there docs on Sibling pages? Do you mean Children's pages? I do have children pages set up.
by siblings, I just mean other pages on the same level, the one's that share the same parent.
Attached is a sitemap. Just to make sure I'm doing it right. Note products one and two. There will be like 50 products for people to scroll through. you think that too much for this type of a thing?
If there is a work around for something like this or an alternative (something easier). I'm all ears.
I'm confused as to why its not working. Any advise would be great!
bryan - which page on this site map is using the page type that you added this code to?
All the interior pages are left_sidebar.php but the ones I'm trying to do this with are product_one and product_two
just to test something, can you create a product_three page on the same level, and then view the product_two page and see if you still get the error.
it may be that since product_one has no previous page and product_two has no next page that is unable to call the getCollectionPath function on that object. That is essentially what the error you posted is saying - that $nextCollectionURL is not actually a collection object.
it may be that since product_one has no previous page and product_two has no next page that is unable to call the getCollectionPath function on that object. That is essentially what the error you posted is saying - that $nextCollectionURL is not actually a collection object.
I'm getting the same error as i was before. One the same line of code.
<div id="sectionPaging" style=""> <? $nextCollectionURL=$nextCollection->getCollectionPath(); if( !strlen($nextCollectionURL) ) $nextCollectionURL='?cID='.$nextCollection->cID; $prevCollectionURL=$previousCollection->getCollectionPath(); if( !strlen($prevCollectionURL) ) $prevCollectionURL='?cID='.$previousCollection->cID; ?> <div style="float:right"> <a href="<?=View::url( $nextCollectionURL )?>"><? /*$nextCollection->getCollectionName()*/ ?>Next Entry È</a> </div> <a href="<?=View::url( $prevCollectionURL )?>">Ç Previous</a> </div>
where did you put the code for the view function? it sounds like $nextCollectionURL might not even be getting defined.
Under the root folder there is a folder called "controllers". Then I made a new folder called "page_types" and created a file called "left_sidebar.php"
The code in this file is the following
Then I went into my theme directory and in the left_sidebar.php I added this code.
I think this is what Tony was telling me to do. Am I doing things right so far? I've never actually worked in the controllers folder before so I'm not for sure if I did that process right.
This is something I found in the source code...
<b>Fatal error</b>: Call to a member function getCollectionPath() on a non-object in <b>/var/www/vhosts/site.com/subdomains/spark/httpdocs/themes/themename/left_sidebar.php</b>
The code in this file is the following
<?php function view(){ $this->set( 'nextCollection', $this->getNextCollection() ); $this->set( 'previousCollection', $this->getPreviousCollection() ); } function getNextCollection(){ global $c; if(!$this->otherCollectionsLoaded) $this->loadOtherCollections(); foreach($this->otherCollections as $photoCollection){ if(!$firstCollection) $firstCollection=$photoCollection; if( $collectionFound ) return $photoCollection; if( $photoCollection->cID == $c->cID ) $collectionFound=1; } return $firstCollection; }
Viewing 15 lines of 34 lines. View entire code block.
Then I went into my theme directory and in the left_sidebar.php I added this code.
<div id="sectionPaging" style=""> <? $nextCollectionURL=$nextCollection->getCollectionPath(); if( !strlen($nextCollectionURL) ) $nextCollectionURL='?cID='.$nextCollection->cID; $prevCollectionURL=$previousCollection->getCollectionPath(); if( !strlen($prevCollectionURL) ) $prevCollectionURL='?cID='.$previousCollection->cID; ?> <div style="float:right"> <a href="<?=View::url( $nextCollectionURL )?>"><? /*$nextCollection->getCollectionName()*/ ?>Next Entry »</a> </div> <a href="<?=View::url( $prevCollectionURL )?>">« Previous</a> </div>
I think this is what Tony was telling me to do. Am I doing things right so far? I've never actually worked in the controllers folder before so I'm not for sure if I did that process right.
This is something I found in the source code...
<b>Fatal error</b>: Call to a member function getCollectionPath() on a non-object in <b>/var/www/vhosts/site.com/subdomains/spark/httpdocs/themes/themename/left_sidebar.php</b>
do you have the right class name for the page type controller? i believe it would have to look like this:
class LeftSidebarPageTypeController extends Controller
oh, and the "loadOtherCollections" function needs this at the beginning:
in order to create the PageList object.
Loader::model('page_list');
in order to create the PageList object.
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class LeftSidebarPageTypeController extends Controller function view(){ $this->set( 'nextCollection', $this->getNextCollection() ); $this->set( 'previousCollection', $this->getPreviousCollection() ); } function getNextCollection(){ global $c; if(!$this->otherCollectionsLoaded) $this->loadOtherCollections(); foreach($this->otherCollections as $photoCollection){ if(!$firstCollection) $firstCollection=$photoCollection; if( $collectionFound ) return $photoCollection; if( $photoCollection->cID == $c->cID ) $collectionFound=1; }
Viewing 15 lines of 38 lines. View entire code block.
yeah, that looks right to me, but don't forget the opening "{" for the class
Its working now nicely. just need to style it! Thanks so much for the help I really appreciate it!
p.s.Did you get my e-mail?
p.s.Did you get my e-mail?
Thanks for this.
I've got this working fine but my question is how do we get it to work on child pages as it seems only to be going through the main pages and not the children. Or am I missing something.
I've got this working fine but my question is how do we get it to work on child pages as it seems only to be going through the main pages and not the children. Or am I missing something.
this example should navigate between all siblings, or pages that are on the same level. ie. those pages with the same parent page.
I'm hoping to make a block of this sometime soon. We will see how that goes.
I've made this into a block and it's working great. I'll post it to the marketplace sometime soon.
I'm struggling with the same function. Could you share your block?
I plan on submitting it to the market place soon. If you need it before why don't you e-mail me. I'd be happy to help out.
sorry bryan, i beat you too it ;-)
the next previous block is now live here:
http://www.concrete5.org/marketplace/addons/next-previous/...
the next previous block is now live here:
http://www.concrete5.org/marketplace/addons/next-previous/...
Yea I noticed that. It's okay though, your version is much more in depth I'm sure. Mine was more so just practice to get better at making blocks and learning PHP. Any tips for that Tony?
Tony, you are awesome! Thank you for figuring this out AND giving it away for free. This is the kind of core element stuff that is really going to make C5 much more competitive with stuff like CMS Made Simple from a non-expert developer point of view (ie. my point of view).
Question: Is there a way to write this functionality into a specific template without having to Add the block to each individual page? For example, I made 2 pages and I stuck the Prev Next block on page 1, but not on page 2 yet:
http://php.22graphics.com/Concrete5/index.php?cID=74...
Both pages use the same template. I'd like to hard-code the Prev Next code in the template so that every time the user selects that type of template, it's already got the Prev Next buttons on the bottom. Otherwise, every time they add a page, they're going to have to add this, too. It would be better for the end user if it was just already there.
Question: Is there a way to write this functionality into a specific template without having to Add the block to each individual page? For example, I made 2 pages and I stuck the Prev Next block on page 1, but not on page 2 yet:
http://php.22graphics.com/Concrete5/index.php?cID=74...
Both pages use the same template. I'd like to hard-code the Prev Next code in the template so that every time the user selects that type of template, it's already got the Prev Next buttons on the bottom. Otherwise, every time they add a page, they're going to have to add this, too. It would be better for the end user if it was just already there.
cool, glad you dig it. here's an example of hardcoding the next previous block into a page type:
$bt = BlockType::getByHandle('tony_next_previous'); $bt->controller->nextLabel = 'Next Collection'; $bt->controller->previousLabel = 'Previous'; $bt->controller->showArrows =1; $bt->controller->loopSequence=1; //$bt->render('templates/footer_bar'); $bt->render('view');
Cool! Tried it, it works! Only a few lines of code, too. Thank you again!
Is there a specific code for "exclude system pages" (when hard-coding into template)?
EDIT: I think I got it! Looked through controller.php and found "excludeSystemPages" so it's probably something like…right?
I guess I need to set up a Parent/Child relationship (?) because on the last post page, the Next button brings me to the Members page rather than looping back to the beginning.
See:http://php.22graphics.com/Concrete5/index.php?cID=78...
Is there a specific code for "exclude system pages" (when hard-coding into template)?
EDIT: I think I got it! Looked through controller.php and found "excludeSystemPages" so it's probably something like
$bt->controller->excludeSystemPages=1;
I guess I need to set up a Parent/Child relationship (?) because on the last post page, the Next button brings me to the Members page rather than looping back to the beginning.
See:http://php.22graphics.com/Concrete5/index.php?cID=78...
C5 should include this block in the core. It's really a great add on.
Bryan, have you been using the add-on with great success? Do you know how to limit it to only a certain section of pages? I'm thinking I need a Parent/Child relationship between the pages, but not sure if that's the case or how to go about it.
Yea I've used it before and it worked great. I'm not for sure if its possible to have a parent/child relationship the way you want it to.
Perhaps "Parent/Child" is the wrong terminology... Not sure what you'd call it, though. I just basically want to cycle through a Portfolio section and not jump any other sections.
try adding this line before the render:
$bt->controller->excludeSystemPages=1;
btw, you can normally figure out what the configuration variables are named by looking at the blocks db.xml file.
$bt->controller->excludeSystemPages=1;
btw, you can normally figure out what the configuration variables are named by looking at the blocks db.xml file.
first, add something like this to the page type controller:
And then add something like this to your page type: