Search

I've been wanting to do a redesign of my blog for some time now and have been thinking about a way to easily create a "previous" and "next" entry links to my content pages.

I did a bit of research on the forums and it seems that people are implementing this effect in a roundabout way.

I was thinking about creating an extension that allows you to specify, in a datasource, how many previous and next entries, relative to the position of the current entry, to include within a particular datasource.

Obviously, this would be best for datasources that pull a single entry at a time, otherwise the resulting XML can become quite large (and redundant).

I know how I'd go about doing this and think it would be quite fun once I finish up my webhooks extension.

What do you guys think?

Im in favor for this plugin. Im planning to use it on a photobook I will place on my website.

Roelof

Hm, since pagination/nextprev can be quite tricky, I am not sure if this will be that helpful. See "next" and "previous" depends on what field you're sorting by, what filters are being set etc... So your extension would have to recreate most of what's provided by Datasources and the DS editor.

I don't think that creating two additional datasources, one going forwards, one backwards is that much of a problem (also since the datetime field now supports much more detailed filtering).

Yeah, I implemented this fairly simply with a single datasource and some XSLT.

<div id="project-detail-navigation">

    <div id="other-projects">
        <h3>Check out some of our other projects</h3>
    </div><!--/#other-projects-->

    <!-- Next project link -->
    <xsl:choose>
        <xsl:when test="/data/projects-listing/entry[@id = current()/@id + 1]">
            <xsl:apply-templates select="/data/projects-listing/entry[@id = current()/@id + 1]" mode="project-link" >
                <xsl:with-param name="rel" select="'next'"/>
            </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select="/data/projects-listing/entry[1]" mode="project-link">
                <xsl:with-param name="rel" select="'start'"/>
            </xsl:apply-templates>
        </xsl:otherwise>
    </xsl:choose>

    <!-- Previous project link -->
    <xsl:choose>
        <xsl:when test="/data/projects-listing/entry[@id = current()/@id - 1]">
            <xsl:apply-templates select="/data/projects-listing/entry[@id = current()/@id - 1]" mode="project-link">
                <xsl:with-param name="rel" select="'prev'"/> 
            </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select="/data/projects-listing/entry[last()]" mode="project-link">
                <xsl:with-param name="rel" select="'end'"/> <!-- There is no 'end' value for a@rel, but it's here for completness -->
            </xsl:apply-templates>
        </xsl:otherwise>
    </xsl:choose>
</div>

And the basic link-building template:

 <xsl:template match="projects-listing/entry" mode="project-link">
    <xsl:param name="rel"/>
    <a href="{$root}/work/{name/@handle}/" rel="{$rel}" title="{homepage-summary}">
        <xsl:apply-templates select="image" mode="filter">
            <xsl:with-param name="filter" select="'project-link'" />
        </xsl:apply-templates>
        <span>
            <xsl:value-of select="name" />
        </span>
    </a>
</xsl:template>

It's pretty verbose - I'm sure someone could do the same thing in far less lines, but it worked for me :D

This might be out of interest: http://getsymphony.com/discuss/thread/256/

Wilhelm did say:

I did a bit of research on the forums and it seems that people are implementing this effect in a roundabout way.

And he's right, there are lots of ways to implement this. Wilhelm, if you've got a generic way of implementing this then I'd love to hear it. I'm not sure how you'd approach it, but I'd like to see how it compares to other methods we've used.

Existing methods usually require one of several limitations:

  • adding a date field or the Order Entries extension to entries and then using a second data source to get the next/prev entries
  • incrementing/decrementing the entry ID by 1 (very brittle, assumes entry IDs are consecutive)

The most generic solution, as I see it, would be to have one data source, which is used to get an entry as usual. But the data source could use an output parameter (Symphony 2.3 will support multiple output params) to provide the previous and next entry ID only. You then use data source chaining to look up these IDs and return the data you need to build hyperlinks.

What did you have in mind?

Symphony 2.3 will support multiple output params

Nick,

is this still true? If so, can you give an example how to approach this? Is there by any chance a possibility to make this work with the search index extension (I know it’s not supported anymore)? I have tried finding a way to do this via the get-param-per-page and some math, but I failed …

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details