I'm a little bit late to the party but figured I'd add my insights...
I had to do this with a bit more of a difficult example. I was pulling posts from 6 blogs that all needed to feed onto the homepage in chronological order. I altered the BlogListPosts.xslt and created a BlogListHomePosts.xslt
I inserted this macro on the homepage template and every time I saw this line, or anything similr
This worked very well for me. I did make a few changes so that it would work without the use of div tags. I needed to do this so that I could use it inside of jquery tools tabs which don't like the extra divs.
One last fix. Because blog for umbraco creates a directory structure like 2010 > 4 > 3 and not 2010 > 04 > 03 when you list the directory contents it list it alphabetically like 1, 10, 2, 3, 4 when it needs to be 1, 2, 3, 4, 10. If we change a couple of lines everything turns out ok:
I was wondering if anyone had updated this to the 4.5.2 schema yet - I'm spanking new to Umbraco (picking it up very quickly - it's awesome) but can't get this to work and wondering if it is because its out of date?
In case other people are newbies like me, put Duncan's code in a macro, and then there are a couple values you need to replace in the code - you'll see what I mean.
The good news is - the page loads. The bad news is, my list of blog entries is not being displayed. I'm using 4.7.1, and I've copied Duncan's as shown here:
Latest blog entries on homepage
Hi! I am new to Umbraco and I have just installed Blog 4 Umbraco.
My question is: is it possible to show the latest n blog entries on the homepage?
It is possible. This example will bring back 3 items:
Thank you very much!!!
I will try to implement your suggested solution as soon as I understand it!
ok, there may be a bit more there than you need. If you have any questions just ask.
And during development I suggest hard-coding the newssource variable i.e.
umbraco.library:GetXmlNodeById(1193)
where 1193 is the node id for your blog
I'm a little bit late to the party but figured I'd add my insights...
I had to do this with a bit more of a difficult example. I was pulling posts from 6 blogs that all needed to feed onto the homepage in chronological order. I altered the BlogListPosts.xslt and created a BlogListHomePosts.xslt
I inserted this macro on the homepage template and every time I saw this line, or anything similr
I changed it to
This grabbed all the newest posts from every blog and spat them out onto the homepage. It worked quite nicely.
This worked very well for me. I did make a few changes so that it would work without the use of div tags. I needed to do this so that I could use it inside of jquery tools tabs which don't like the extra divs.
I also added a truncating effect so that it works well as a summary. Thanks for all of your help!
Cheers
Ok so I updated it even more to remove any html tags for consistant presentation.
One last fix. Because blog for umbraco creates a directory structure like 2010 > 4 > 3 and not 2010 > 04 > 03 when you list the directory contents it list it alphabetically like 1, 10, 2, 3, 4 when it needs to be 1, 2, 3, 4, 10. If we change a couple of lines everything turns out ok:
Wow one last entry. So I made this change so that the data on the main homepage ALWAYS shows in numeric order rather than the node sortOrder ID.
Cheers
Hello
I was wondering if anyone had updated this to the 4.5.2 schema yet - I'm spanking new to Umbraco (picking it up very quickly - it's awesome) but can't get this to work and wondering if it is because its out of date?
Thanks in advance!
Managed to crack it already, here is the code if anyone is interested (lists 3 blog posts on the home page):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets uForum uForum.raw tagsLib BlogLibrary ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(NODE ID OF YOUR BLOG NODE)" />
<xsl:variable name="allowable-length" select="165"/>
<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="$newsSource/descendant-or-self::* [@isDoc and name() = 'BlogPost']">
<xsl:sort select="./../../../@sortOrder" order="descending" />
<xsl:sort select="./../../@sortOrder" order="descending" />
<xsl:sort select="./../@nodeName" order="descending" />
<xsl:sort select="@sortOrder" order="descending" />
<xsl:if test="position()<= HOW MANY DO YOU WANT TO DISPLAY?">
<xsl:variable name="textOnly">
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="./bodyText" />
</xsl:call-template>
</xsl:variable>
<h3><xsl:value-of select="@nodeName" /></h3><xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> - <a href="{umbraco.library:NiceUrl(@id)}">Read More</a>
<p>
<xsl:value-of select="substring($textOnly, 0, $allowable-length)" disable-output-escaping="yes"/>
<xsl:if test="string-length(.) > $allowable-length">
<xsl:text>...</xsl:text>
</xsl:if>
</p>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks for that Duncan :D
And latest comments from blog? Is it possible via LINQ?
Hey Biagio,
The comments are held in a standard SQL Server table (for some reason?) , so you could use Linq in the normal way I imagine.
Rich
Duncan Gunn, thanks. Awesome code.
In case other people are newbies like me, put Duncan's code in a macro, and then there are a couple values you need to replace in the code - you'll see what I mean.
The good news is - the page loads. The bad news is, my list of blog entries is not being displayed. I'm using 4.7.1, and I've copied Duncan's as shown here:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets uForum uForum.raw tagsLib BlogLibrary ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(1068)" />
<xsl:variable name="allowable-length" select="165"/>
<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="$newsSource/descendant-or-self::* [@isDoc and name() = 'BlogPost']">
<xsl:sort select="./../../../@sortOrder" order="descending" />
<xsl:sort select="./../../@sortOrder" order="descending" />
<xsl:sort select="./../@nodeName" order="descending" />
<xsl:sort select="@sortOrder" order="descending" />
<xsl:if test="position()<= 3">
<xsl:variable name="textOnly">
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="./bodyText" />
</xsl:call-template>
</xsl:variable>
<h3>
<xsl:value-of select="@nodeName" /></h3><xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> - <a href="{umbraco.library:NiceUrl(@id)}">Read More</a>
<p>
<xsl:value-of select="substring($textOnly, 0, $allowable-length)" disable-output-escaping="yes"/>
<xsl:if test="string-length(.) > $allowable-length">
<xsl:text>...</xsl:text>
</xsl:if>
</p>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks in advance...
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.