Forum

Thread tagged as: Question

List and Detail page - how can I add a link to next and previous item of list in...

Have implemented the list and detail page from Solutions > Architecture... On the detail page I am wanting to add links "Back" and "Next" to other items in the list. (Currently these links are inside the template). Thought I could use "prev_url" / "next_url" but only populates these as current URL?

Stuart Farrell

Stuart Farrell 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

prev_url and next_url are used in list pagination. You're showing a list of one when you show a detail page.

You can use perch_content_custom() to filter for the previous and next items. What field are you sorting by?

Filtering by slug... just using the standard example code with our templates:


perch_content_custom('Weddings', array( 'template' => 'weddings_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, ));
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which field are you sorting by when you consider previous and next items?

Have not specified a sort order or ID, so assume it's the default order of items in the region. Should we add an ID to sort by? Would be "title" in that case.

Is there not an ID we can use of the order of the item in region?

Will we need to pull these links to prev/next outside of the html template and into PHP?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'll see if I can put an example together.

OK thanks, that would be awesome.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks! You guys rock!! Will give it a whirl later today and let you know how we go.

Added this in and it works perfectly, thanks again. You guys give amazing support!

Drew McLellan

Drew McLellan 2638 points
Perch Support

No problem!

Hi Drew I have followed these instructions but I keep getting the following PHP error:

PHP Warning: Illegal string offset '_sortvalue' in C:\Websites\kendalls\public-media-relations.php on line 91

Using the very latest version of perch.

Apologies I have fixed that issue, simple typo!

However is there an easy way of getting to go back to the beginning item when it has gone through all of the items. So it just keeps going back to the beginning item after the last item?