Search

How would I count the amount of rows in a certain month? Essentially, I just want a “20 jobs posted this month!” line on the front page.

It’s a lame question, but I’m still trying to get my head around how Symphony works!

Select all of them and then use count() in your XSLT (easy but slow).

Or edit the DS manually (fast but harder).

Would I have to set up a new data source that only retrieved the last month of posts?

Probably, yes.

No, wait. You can fetch pagination-data from every DS. Thats quicker than counting them in the XSLT.

But still, if you don’t already have a DS for fetching last months entries, you’ll have to create a new one, yes.

Create a new DS “Posts Last Month” from your posts section. Add a filter on a date field to filter entries by either the current month or the last thirty days.

“Show a maximum of 1 results” and leave it showing “page 1 of results”. Then select “pagination” in the XML Output and attach to your page.

You should get a DS with a <pagination /> element inside it with a total-entries attribute as a count.

This is more efficient than selecting all entries into your XML and counting them.

Awesome, thanks for that chaps. I’m gradually getting the hang of this!

Although the solutions posted above are probably easier on first sight, you can use XSLT to count the entries that are posted this month from your datasource with all jobs. I don’t like to add multiple data sources when only one is necessary. Since there is no simple function that (I know of that) can give you the date a month ago you will have to write this yourself.

For instance, you can use this XSLT in your jobs template:

<xsl:template match="jobs">
    <xsl:param name="one-month-ago">
        <xsl:choose>
            <xsl:when test="$this-month = '01'">
                <xsl:value-of select="concat($this-year - 1, '-12-', $this-day)" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat($this-year, '-', format-number(string($this-month - 1), '00'), '-', $this-day)" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="count-this-month" select="count(entry[translate(date, '-', '') &gt; translate($one-month-ago, '-', '')])" />
    <p><xsl:value-of select="$count-this-month" /> jobs posted this month!</p>
</xsl:template>

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