I would like to apply what this macro does only to the posts within the last month. Is there any way I can surround this whole part with another sort that only reads the posts within the last month?
You should be able to use a predicate on your node selector to select only those articles within a certain range from today. Umbraco has some XSLT extension methods available to help with this, namely: FormatDateTime, CurrentDate and DateDiff. It should allow you to do something like this (not tested!):
<!-- Get current date -->
<xsl:variable name="currentDate" select="substring-before(umbraco.library:CurrentDate(), 'T')"/>
<!-- Add a predicate to node selection to get articles where the difference between blogPostDate property
and currentDate variable is less than 43829 minutes(! which equates roughly to 1 month) -->
<xsl:for-each select="$currentPage/ancestor-or-self::umbBlog//umbBlogPost[umbraco.library:DateDiff(umbraco.library:FormatDateTime(blogPostDate,'yyyy-MM-dd'), $currentDate, 'm') < 43829]">
<xsl:sort select="count(BlogLibrary:GetCommentsForPost(@id)//comment)" data-type="number" order="descending" />
<xsl:if test="position()< 5">
<xsl:variable name="text" select="umbraco.library:StripHtml($currentPage/@nodeName)" />
<a href="{umbraco.library:NiceUrl(@id)}" class="popularPostsClass"><xsl:value-of select="./@nodeName" disable-output-escaping="yes"/></a>
<br/>
</xsl:if>
</xsl:for-each>
and I hide the rest that I don't need through CSS. but I will give your version a try as I would rather avoid having a huge list hidden by CSS. Thanks, I will get back to you with how it goes!
Filter posts within last month
Hello,
I have the following Macro:
I would like to apply what this macro does only to the posts within the last month. Is there any way I can surround this whole part with another sort that only reads the posts within the last month?
Thank you!
Hi Alexandru,
You should be able to use a predicate on your node selector to select only those articles within a certain range from today. Umbraco has some XSLT extension methods available to help with this, namely: FormatDateTime, CurrentDate and DateDiff. It should allow you to do something like this (not tested!):
Hopefully this gets you started...
Hi Dan,
For now I am using this:
and I hide the rest that I don't need through CSS. but I will give your version a try as I would rather avoid having a huge list hidden by CSS. Thanks, I will get back to you with how it goes!
It is errorless but it seems the predicate won't work. Regardless of the number of minutes I put in, it still reads older posts.
Hi Alexandru,
There are quite a lot of things that can be done to help in debugging this, for example, try putting this inside your loop and see what it returns:
It seems I am getting negative values. Let me try to fix that and see if there's any change.
Aye, fixed it. It should be '> [negative value of timespan]'
you should change this in your post so that others can have the right version too :)
It's this:
Ah okay, try this as the predicate in that instance:
Thanks for the support!
is working on a reply...