Forum

Thread tagged as: Question

Creating link rel="prev" link rel="next" in the area using 'product_prev...

I have successfully added the prev next links to a List/Detail set up. For SEO reasons would like to add rel="prev" link rel="next" in <head> area. ie

<link rel="next" href="https://www.domain.co.uk/subfolder/page3"/>  

<link rel="prev" href="https://www.domain.co.uk.gridhosted.co.uk/subfolder/page1" />  

Have created a template variant of prev next and added same code from body area into the head

Template canon.html

<perch:if exists="is_prev">
<link rel="prev" href="/corporate-video/portfolio-detail.php?s=<perch:content id="slug" type="slug" />" />
<perch:else />
<link rel="next" href="/portfolio-detail.php?s=<perch:content id="slug" type="slug" />"/>
</perch:if> 

Head Code

<?php
perch_content_custom('CorporateVideo', array(
   'page' => '/corporate-video/index.php',
    'template'   => 'canon.html',
    'filter'     => '_order',
    'match'      => 'gt',
    'value'      => $result[0]['_sortvalue'],
    'sort'       => '_order',
    'sort-order' => 'ASC',
    'count'      => 1,
));
?>
<?php
PerchSystem::set_var('is_prev', true);

perch_content_custom('CorporateVideo', array(
    'page' => '/corporate-video/index.php',
    'template'   => 'canon.html',
    'filter'     => '_order',
    'match'      => 'lt',
    'value'      => $result[0]['_sortvalue'],
    'sort'       => '_order',
    'sort-order' => 'DESC',
    'count'      => 1,
));
?>

It works BUT outputs the SAME first and last page (from the list of pages) on EVERY detail page.

I would be grateful for any help with this. Many thanks

Phil Wragg

Phil Wragg 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where is $result getting set?

Hi Drew

It is in the <body> area where it is working successfully for the Next / Previous visible on the page.

I can see if I put the following into the head area - my SEO <link rel="next" <link rel="prev" does work - but obviously displays the content so no good....but hints at a solution.

<?php
 $result = perch_content_custom('CorporateVideo', array(
     'page' => '/corporate-video/index.php',
     'template' => 'portfolio.html',
     'filter' => 'slug',
     'match' => 'eq',
     'value' => perch_get('s'),
     'count' => 1,
      'skip-template' => true,
    'return-html'   => true,
));
echo $result['html'];
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Remove echo $result['html'];

Ah of course! Many thanks for your help with this, very important to get this right for me. SEO 'audit' pushing my Perch knowledge...which is good for me, although may generate odd question for you.