Next/Prev only showing first and last page in folder

Permalink
I have 40+ portfolio pages in a folder that are all hidden from the top nav. I want to hard-code the previous/next block into the custom portfolio page type. The sample code I found from other posts only outputs the first and last page in the folder.

This is what I tried:
<code>
<?php
$bt_main = BlockType::getByHandle('next_previous');
$bt_main->controller->nextLabel=t('Next');
$bt_main->controller->previousLabel=t('Previous');
$bt_main->controller->parentLabel=t('');
$bt_main->controller->showArrows=1; // set to 0 when false
$bt_main->controller->loopSequence=0; // set to 1 if true
$bt_main->controller->orderBy='display_asc'; // display_desc, display_asc etc...
$bt_main->render('view'); // default block
//$bt_main->render('templates/youtemplatename');
?>
</code>

If I go onto each page individually, I can add the prev/next block manually and it works. I tried adding that block into a stack that I hard-coded onto my template, but that doesn't work. it only shows the first and last page in the folder.

I even tried to add the manually created prev/next block in the default page type and apply to all the children. That too just shows the first and last page in the folder, and not the next/prev page in relation to the current page.

Any ideas?

mattarnzen
 
TeKnoZiz replied on at Permalink Reply
TeKnoZiz
This is the same thing that is happening to me. Instead of hard coding, I am using the Prev/Next block at the bottom of the eCommerce Product Detail page. It just shows me the first and last products. Did you ever find an answer to this?
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
The Previous/Next blocks works like an autonav block and filters out pages marked as "Exclude from Nav".
TeKnoZiz replied on at Permalink Reply
TeKnoZiz
Is this something you can work around? The client doesn't want to have all their products showing up in the menu.
Sadu replied on at Permalink Reply 1 Attachment
Sadu
I ran into this same problem. You can resolve by overriding the controller for the next/previous block.

These instructions are for 5.6.1 and beyond.

1. Create a new folder /blocks/next_previous/
2. Copy /concrete/blocks/next_previous/controller.php into the new folder above.
3. Open up /concrete/core/controllers/blocks/next_previous.php
4. Copy-paste the getNextCollection and getPreviousCollection functions into your new controller.
5. Search for the following code - it should appear once in each function.
&& $page->getAttribute('exclude_nav') != 1

6. Delete this code. Save.
7. Clear cache.

Alternatively, use the controller I have attached (save into /blocks/next_previous/) if you are using 5.6.1.
mattarnzen replied on at Permalink Reply
mattarnzen
Thanks so much Sadu. That worked great except the prev/next is linking to pages based on when they were created and not where they are in the sitemap. Any ideas?

I'm using this code to hard-code it in my template:
<?php
$nav = BlockType::getByHandle('next_previous');
$nav->controller->nextLabel = 'Next Portfolio';
$nav->controller->previousLabel = 'Previous Portfolio';
$nav->controller->parentLabel = '';
//$nav->controller->linkStyle = 'page_name'; //Uncomment this line to use actual page titles for labels
$nav->controller->showArrows = true;
//$nav->controller->orderBy = 'chrono_desc'; //Uncomment this line to sort pages by most recent first (so "next" and "previous" links go in date order, not sitemap order)
$nav->controller->loopSequence = false; //set to true if you want to "wrap around" (clicking "next" on the last item goes to first item, and vice-versa)
$nav->controller->excludeSystemPages = true; //best to always leave this as true
$nav->render('view');
?>
mattarnzen replied on at Permalink Reply
mattarnzen
Sadu,
Any idea why the prev/next is linking to pages based on when they were created and not where they are in the sitemap? See my reply from 4/11.
Sadu replied on at Permalink Reply
Sadu
Try adding the following to your code...
$nav->controller->orderBy= 'display_asc';

If the orderBy is not set to this, a different query runs (which is sorted by DatePublic).
mattarnzen replied on at Permalink Reply
mattarnzen
That worked! Thanks so much.
MathiasB replied on at Permalink Reply
MathiasB
Cool – it works great! Thank You!
But I needed some time to find out that the view.php and the view.css also has to be copied in the new folder. Otherwise I couldn'd edit the appearance of the block.
TeKnoZiz replied on at Permalink Reply
TeKnoZiz
Nevermind, I was able to change the attribute by using Page Search and batch editing the attribute. Now it works fine. Thanks!