I'm using the Fanoe theme and trying to display the blog entries on a page other than the blog overview page. I've tried a number of things here to no avail - any ideas will be greatly appreciated!
I'm using Umbraco 7 and the built in blog that comes with Fanoe.
Ok, but if you write something like this then it should work
@{
//Fetch the blogposts from a certain node id
var blogPosts = Umbraco.Content(1081);
foreach(var blogPost in blogPosts.Children()){
@blogPost.Id <br />
}
}
You're welcome - Good you got it working. I only rendered the ID since I was not sure what content you wanted to render yourself - But be aware that the above code can be fragile if the blogposts node is ever deleted since it relies on that the id exists - It's probably not likely that it will be deleted but it's just never safe to make assumptions - But the liberty to do so also depends on who the editor is and how often the content is edited etc. etc. etc.
Just thought I would mention it - Happy coding! :)
Blog entries on homepage
Hi Folks,
I'm using the Fanoe theme and trying to display the blog entries on a page other than the blog overview page. I've tried a number of things here to no avail - any ideas will be greatly appreciated!
I'm using Umbraco 7 and the built in blog that comes with Fanoe.
Thanks in advance.
Darren
Hi Darren
What approaches have you been trying? Could you share some code?
/Jan
Hi Jan,
I've tried a number of different approaches as listed on the forum here - XLST and macros. Some date from a few years back.
This macro didn't work:
@{IPublishedContent newsNode = Umbraco.Content(1081);}
@foreach (var newsItem in newsNode .Children().Take(4))
{
@{
if (@newsItem.HasValue("newsThumb"))
{
var mediaItem = Umbraco.TypedMedia(@room.GetPropertyValue("newsThumb"));
<img src="@mediaItem.GetPropertyValue("umbracoFile")" />
}
}
<p><a href="@newsItem.NiceUrl()">@newsArticle.Name</a></p>
<p>@newsItem.GetPropertyValue("newsDescription")</p>
}
Neither did this XLST
<?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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="MaxNoChars" select="190" />
<xsl:template match="/">
<xsl:for-each select="$currentPage//ancestor-or-self::doTextpage[@isDoc and showOnHomepage = '1']">
<div class="redPanel">
<h2><xsl:value-of select="@nodeName" /></h2>
<p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(umbraco.library:Replace(current()/bodyText, '&nbsp;', '')), $MaxNoChars, '...')" /></p>
<p><a href="{umbraco.library:NiceUrl(@id)}"> <img src="/img/btnMore.png" alt="read more" tooltip="Read more" align="right" /> </a></p>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hi Darren
Ok, but if you write something like this then it should work
Hope this helps.
/Jan
Hi Jan,
A bit of experimentation and this works:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
//Fetch the blogposts from a certain node id
var blogPosts = Umbraco.Content(1081);
foreach(var blogPost in blogPosts.Children()){
<div class="date">@blogPost.CreateDate.ToLongDateString()</div>
<h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>
<p>@Umbraco.Truncate(blogPost.Introduction, 200, true)</p>
}
}
Thanks for the pointer in the right direction!
Darren
Hi Darren
You're welcome - Good you got it working. I only rendered the ID since I was not sure what content you wanted to render yourself - But be aware that the above code can be fragile if the blogposts node is ever deleted since it relies on that the id exists - It's probably not likely that it will be deleted but it's just never safe to make assumptions - But the liberty to do so also depends on who the editor is and how often the content is edited etc. etc. etc.
Just thought I would mention it - Happy coding! :)
/Jan
is working on a reply...