[英]How to display “number of new” child pages Umbraco XSLT
我要尝试合并两个单独的代码段。
第一个计算子页面的数量并显示一个数字:
例如8个子页面(或子页面,如果只有1个页面)
<xsl:choose>
<xsl:when test="count(child::DocTypeAlias) > 1">
<p><xsl:value-of select="count(child::DocTypeAlias)"/> child pages</p>
</xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="count(child::DocTypeAlias)"/> child page</p>
</xsl:otherwise>
该代码检测页面是否在最近30天内创建:
<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" />
<xsl:if test="$datediff < (1440 * 30)">
<p>New</p>
</xsl:if>
我想将它们结合起来,这样我就可以得到一个子页面数和一个“新”页面数。
例如8个子页面-2个新页面
我尝试了以下操作,但未返回正确的值:
<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" />
<xsl:choose>
<xsl:when test="$datediff < (1440 * 30) and count(child::DocTypeAlias) > 1">
<p><xsl:value-of select="$datediff < (1440 * 30) and count(child::DocTypeAlias)"/> new pages</p>
</xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="$datediff < (1440 * 30) and count(child::DocTypeAlias)"/> new page</p>
</xsl:otherwise>
</xsl:choose>
它返回:“真实的新页面”我不知道如何显示该数字(2个新页面)。
有人可以帮忙吗? 欢呼声,合资企业
仔细查看您为该段指定的内容:
<p>
<xsl:value-of select="
$datediff < (1440 * 30)
and
count(child::DocTypeAlias)"/>
new pages
</p>
您有一个and
,布尔值为左参数,整数为右参数。 投入处理器的步伐:看起来不像您在要求它计算布尔值吗?
由于此表达式包含在已经测试过日期差的when
元素中,因此您(几乎可以肯定)不需要重复$ datediff与43200的比较。(我说“几乎可以肯定”,因为我认为我不会详细了解您的应用程序的逻辑,所以我可能是错的。)我怀疑您想说的是:
<p>
<xsl:value-of select="count(child::DocTypeAlias)"/>
new pages
</p>
你需要在类似的变化otherwise
。
非常感谢Chriztian Steinmeier:
<!-- The date calculation stuff -->
<xsl:variable name="today" select="umb:CurrentDate()" />
<xsl:variable name="oneMonthAgo" select="umb:DateAdd($today, 'm', -1)" />
<!-- Grab the nodes to look at -->
<xsl:variable name="nodes" select="$currentPage/DocTypeAlias" />
<!-- Pages created within the last 30 days -->
<xsl:variable name="newPages" select="$nodes[umb:DateGreaterThanOrEqual(@createDate, $oneMonthAgo)]" />
<xsl:template match="/">
<xsl:choose>
<xsl:when test="count($newPages)">
<p> <xsl:value-of select="count($newPages)" /> <xsl:text> New Page</xsl:text>
<xsl:if test="count($newPages) > 1">s</xsl:if>
</p>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.