Forum

Thread tagged as: Question

Create a next and previous link in list and detail setup

I have created a typical news section using list and detail setup. Is it possible on the detail page to have a 'Next' link to go to the next detail page rather than going back to the list. Many thanks.

Phil Wragg

Phil Wragg 0 points

  • 7 years ago

Where do I add the echo $result['html'];

In the following code? I am just getting blank page still. Many thanks

<?php
if (perch_get('s')) {

 // Detail mode
 perch_content_custom('News', array(
      'template' => 'news_detail.html',
      'filter' => 'slug',
      'match' => 'eq',
      'value' => perch_get('s'),
      'count' => 1,
      'skip-template' => true,
      'return-html'   => true,      
 ));
}

else {

 // List mode
perch_content_custom('News', array(
'template' => 'news_list.html',
'count'=>2,
'sort-order'=>'DESC',
'paginate'=>true
 )); 
}

?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Add the echo wherever in the page you want that HTML to be output.

Hi Drew

I'm going to need your patience.....

Ok list/detail works fine.

I add..as above

'skip-template' => true, 'return-html' => true,

Content disappears

So I need to add echo $result['html']; for it to reappear.

I have tried adding it at various points within the above code and after but no joy should it be wrapped in tags?

Near but not quite I'm afraid.

Please let me know if I'm intruding...

When you're saying echo $result['html'];, you're using PHP to tell your server to print out (or echo) the item in the array variable $result that has the index "html". As it is now, you haven't defined the $result variable yet, so the server can't echo any part of that variable; for all it knows, $result doesn't exist.

To fix this and define $result, just insert $result = before the first perch_content_custom(...) in the code you've posted. Additionally, echo $result['html']; has to appear after this definition. So you'd need something like

<?php
if (perch_get('s')) {

 // Detail mode
$result = perch_content_custom('News', array(
      'template' => 'news_detail.html',
      'filter' => 'slug',
      'match' => 'eq',
      'value' => perch_get('s'),
      'count' => 1,
      'skip-template' => true,
      'return-html'   => true,      
 ));

echo $result['html'];

}

else {

 // List mode
perch_content_custom('News', array(
'template' => 'news_list.html',
'count'=>2,
'sort-order'=>'DESC',
'paginate'=>true
 )); 
}

?>

This works because when skip-template is set to true, perch_content_custom returns an array that you can save as a variable; in this case, $result. When return-html is set to true, the index "html" inside the returned associative array contains the region's HTML.

Many thanks for your help. That's it.