Forum

Thread tagged as: Configuration

Swap previous/next links around

I'm using a list and detail page and creatiing previous next links

https://docs.grabaperch.com/perch/content/functions/how-do-i-link-prev-next/

All good so far apart from the template outputs the "previous" link after the "before" I'd like them the other way round "previous" first if it exists but can't figure how...

<a href="?s=<perch:content id="slug" type="slug" />">
    <perch:if exists="is_prev">← Previous<perch:else />Next Event →</perch:if>
    <perch:content id="eventname" type="text" suppress="true" />
</a>
David Owen

David Owen 0 points

  • 4 years ago
Simon Clay

Simon Clay 127 points

I haven't tested this, but is it a case of switching the perch_content_custom for Previous to be before the perch_content_custom call for the 'Next' on the page?

That's what thought but swapping perch_content_custom makes the function fail.

I fudged it for now by having the second perch_content_custom call a different template name of the same code and use CSS to float left right. It's not quite in the ideal source order. Hence asking the question.

Simon Clay

Simon Clay 127 points

Hi, just running it in dev now...

Swapping the order of the perch_custom_calls is right, but when doing this we also need to unset the is_prev variable before we call the final 'Next' perch_custom_content call

$result = perch_content_custom('Products', array(
            'template'      => 'product.html',
            'page'          => '/products/index.php',
            'filter'        => 'slug',
            'match'         => 'eq',
            'value'         => perch_get('s'),
            'count'         => 1,
            'skip-template' => true,
            'return-html'   => true,
        ));

        echo $result['html'];



// Set the 'previous' variable
        PerchSystem::set_var('is_prev', true);
//Previous call
        perch_content_custom('Products', array(
            'template'   => 'product_prevnext.html',
            'filter'     => '_order',
            'match'      => 'lt',
            'value'      => $result[0]['_sortvalue'],
            'sort'       => '_order',
            'sort-order' => 'DESC',
            'count'      => 1,
        ));


// Unset the 'previous' variable
    PerchSystem::unset_var('is_prev');  
// Next call
    perch_content_custom('Products', array(
            'template'   => 'product_prevnext.html',
            'filter'     => '_order',
            'match'      => 'gt',
            'value'      => $result[0]['_sortvalue'],
            'sort'       => '_order',
            'sort-order' => 'ASC',
            'count'      => 1,
        ));

Thanks for looking at this!

Simon Clay

Simon Clay 127 points

Hey, no problem. :) I'd not used it before and was interested to see how it works.

It's a neat solution to extend the functionality of list and detail pages.