I currently have 2 documents types for my news section:
News - this shows an overview of all published news items
NewsItem - this is the actual news item itself
However, I wish to have a section on my homepage where I can show the teaser from the latest published news item. I have a teaser field called "newsTeaser" inside my NewsItem document type - but I'm unsure how to show this on my homepage in my main template.
Here's a similar script I've used to display the latest 3 news on the homepage
Pay close attention to the sort, the limiting to 3 and the properties used. You'll have to change these! This also assumes a property called newsDate with a datepicker, but you could just use the publish date
@Jan Good point. I have a lot of little snippets like that (as I'm sure lots of devs do), that would really be great in the wiki. I'll try to get time to genericise them and upload. It would help stop these little snippets getting lost on the forum.
@garry, I should note that the snippet above requires a content picker as a macro paramater to select which news page to take the news items from. In your case you migth want to grab all news items below the homepage, in which case get rid of
I've been away over the weekend so only just had chance to check the post. Thanks for all the replies, I'm currently trimming down your reply Dan, but there is a structural issue concerning my XSLT. The actual news item and teaser only appear on my news page - and not from my home page. So it seems this is working - but theres some code missing - or an incorrect parameter for this to display on the homepage. Here is my XSLT if you can spot where I'm going wrong - I presume its something to do with $currentPage as it is not searching through the page structure properly:<code>
<xsl:for-each select="$currentPage/node [string(data [@alias='newsTeaser']) != '' and string(data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias='NewsItem' ]">
Needed to be changed to:
<xsl:for-each select="$currentPage/node/node [string(data [@alias='newsTeaser']) != '' and string(data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias='NewsItem' ]">
So the extra /node/ would work its way down to this item. Now - if I want to further extend this so that I can show this news item on every page - how would you configure the code so it specifically searches the news section - without needing to specify the depth using "$currentPage/node" - as this level will vary depending where you are on the site.
Hi I found this post but am having trouble displaying news items on the homepage, Its currenlty blank, my xslt looks like this (NewsItem is the doc type name)
Creating a home page news item
Hi everyone,
I currently have 2 documents types for my news section:
However, I wish to have a section on my homepage where I can show the teaser from the latest published news item. I have a teaser field called "newsTeaser" inside my NewsItem document type - but I'm unsure how to show this on my homepage in my main template.
Any help would be great, Garry.
Just create an xslt file where you get the latest news item and insert the macro on your homepage template.
Here's a similar script I've used to display the latest 3 news on the homepage
Pay close attention to the sort, the limiting to 3 and the properties used. You'll have to change these! This also assumes a property called newsDate with a datepicker, but you could just use the publish date
Dan
Hi Dan
Great example. Have you put it into the wiki? If not I would encourage you to do it :)
/Jan
@Jan Good point. I have a lot of little snippets like that (as I'm sure lots of devs do), that would really be great in the wiki. I'll try to get time to genericise them and upload. It would help stop these little snippets getting lost on the forum.
@garry, I should note that the snippet above requires a content picker as a macro paramater to select which news page to take the news items from. In your case you migth want to grab all news items below the homepage, in which case get rid of
and change
to
Hope this helps,
Dan
Hi guys,
I've been away over the weekend so only just had chance to check the post. Thanks for all the replies, I'm currently trimming down your reply Dan, but there is a structural issue concerning my XSLT. The actual news item and teaser only appear on my news page - and not from my home page. So it seems this is working - but theres some code missing - or an incorrect parameter for this to display on the homepage. Here is my XSLT if you can spot where I'm going wrong - I presume its something to do with $currentPage as it is not searching through the page structure properly:<code>
Oooh think I've found it, it was this line:
Needed to be changed to:
So the extra /node/ would work its way down to this item. Now - if I want to further extend this so that I can show this news item on every page - how would you configure the code so it specifically searches the news section - without needing to specify the depth using "$currentPage/node" - as this level will vary depending where you are on the site.
Thanks again, Garry.
Should find all news items throughout the site, no matter where you are.
Dan
Excellent, thanks very much everyone, especially Dan.
Garry.
Hi I found this post but am having trouble displaying news items on the homepage, Its currenlty blank, my xslt looks like this (NewsItem is the doc type name)
<?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="html" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />
<!--<xsl:variable name="NewsItem" select="umbraco.library:GetXmlNodeById(/macro/NewsItem)" />-->
<!--<xsl:for-each select="$NewsItem//node [string(data [@alias='newsDate']) != '' and string(data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias='NewsItem' ]">-->
<xsl:for-each select="$currentPage/ancestor-or-self::root//node [string(./newsDate) != '' and string(./umbracoNaviHide) != '1' and @nodeTypeAlias='NewsItem' ]">
<xsl:sort select="current()/newsDate" order="descending" />
<xsl:if test="position() <= 1">
<h2><a title="View full story of {@nodeName}" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="./newsHeading"/></a></h2>
<p class="date"><xsl:value-of select="newsDate"/></p>
<p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./newsBodyText), 100,'...')"/></p>
<p class="bg-greenBtn"><a title="Continue reading {@nodeName}" href="{umbraco.library:NiceUrl(@id)}"><span>Continue reading</span></a></p>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I know this is an old post, but any help will be much appreciated
is working on a reply...