Reputation: 16858
I have an Umbraco site for personal use that I want to also use as a blog.
I'm trying to put together the XSLT to grab the top three posts from the nodes in the Blog tree (node id = 1063) and display these on a tab page that is incorporated into the front page.
The following image illustrates the node hierarchy:
With my extremely limited appreciation of XSLT, I'm unable to grab the node ID of the "Blog" id and take the 3 pages below that to display in the "Top Posts" part of my site which is found under the "Frontpage Tabs" node. All the examples I find work with the "current page", which is typically the top-level node, "Personal Site".
How should I accomplish this?
EDIT
The rendered output is actually blank on the published page (even after republishing the entire site) but the preview displayed in the back office rich text editor for the "Top Posts" tab content is displayed correctly.
The XSLT I'm using looks like this:
<xsl:template match="/">
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById(1063)/umbBlogPost [@isDoc]">
<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li>
</xsl:for-each>
</ul>
</xsl:template>
The HTML shown in the tab's Rich Text Editor looks like this:
<div umb_macroalias="Dn.BlogListTopThreePosts" ismacro="true" onresizestart="return false;" umbversionid="cb1efb8d-f58c-424b-9c12-df14ac5652d9" umbpageid="1115" title="This is rendered content from macro" class="umbMacroHolder"><!-- startUmbMacro -->
<ul>
<li><a href="/blog/test-post.aspx">Test Post</a></li>
</ul>
<!-- endUmbMacro --></div>
I'll update this post again once I've retrieved the XML from the Database (if that's helpful). The issue is less the actual data as it is the disconnect between the published page and the back end.
Upvotes: 2
Views: 2009
Reputation: 9061
I've not tested this (I don't have your data), but use the position() method to stop processing after a set number of iterations (some good xslt examples here).
<xsl:variable name="blogRoot" select="1063"/>
<xsl:for-each select="umbraco.library:GetXmlNodeById($blogRoot)/umbBlogPost [@isDoc]">
<xsl:if test="position() <= 3">
<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
</li>
</xsl:if>
</xsl:for-each>
If you were using razor, you could do something like:
@using uComponents.Core;
@using uComponents.Core.uQueryExtensions;
@{
var topThreeBlogPosts = @uQuery.GetNodesByType(<blog post doc type>).Take(3);
foreach(blogItem in topThreeBlogPosts)
{
<li><a href="@blogItem.NiceUrl">@blogItem.nodeName</a></li>
}
}
Upvotes: 1