I'm using the newsList.xslt for my news section. It has the posibility to select a featured article which always is displayed at top.
But when I haven't selected a top article, it still add the featured_news class to the first list item. This cause when I'm using paging that the latest article is shown at the top on both page 1 and 2. You can take a look at this page: http://oldengaard.dk/da/nyheder.aspx
How could it only use the featured article if I have picked a news item?
This is intentional, although perhaps now that you mention it is a little unintuitive (and unwanted). If this still affects you (or anyone else who might stumble onto this) you can change newslist.xslt with the following
Change (starting line 23)
<xsl:variable name="featuredArticle">
<xsl:choose>
<xsl:when test="string($currentPage/newsFeaturedArticle) != ''">
<xsl:value-of select="$currentPage/newsFeaturedArticle" />
</xsl:when>
<xsl:otherwise>
<!-- should support autofolders if we use // -->
<xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='NewsItem']">
<xsl:sort select="current()/newsDate" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="current()/@id" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Before I did that it has the featured article on top of all pages in the news list.. and when no newsitem was selected as featured, it still has added the featured class to the top newsitem, which caused that it was on all pages too in the top.
It isn't necessary in my case to have this feature, but I might need it someday.
No I didn't find the solution I was looking for... but it wasn't a must for me having the featured article in the news list.. so I decided to out comment that part:
Otherwise I had the featured article on all pages in top of page. And when no featured article was selected it still added a class for the top article and considered the top article on each page as a featured article.
I also changed a bit in the paging, so instead of ?page=0 , ?page=1 etc. ....... I have ?page=1 , ?page=2 etc...
Yea, I don't think you should have the /Image/ part ...
It's rarely I use the Image part after umbracoFile.. I think it can be used for check if a folder contains different file types it should only get images..
and I think the current() part only can be used inside a loop. The code a wrote earlier was just a simple way to display an image somewhere in the template.
here is my full xslt for showing news ..... newsImage is media picker type... I have image type files uploaded in media ... but still not showing image
and current()newsImage with ./newsImageis not making any difference ... but yes ... my xslt is not showing image... there is some problem... so is itr because of that it is not showing rss feed also?
Okay, what about the normal html code... do you got a XSLT error in frontend or? If you use Firefox and have Firebug installed you can see what you have in the code.. Safari and Chrome have a similar tool.
If you want to set up a rss feed for the newlist I think you should create a xslt file for the rss, where it has the values from the news items... and a xslt file for the normal newslist.
Is the newslist working on one of the pages? Then you always can create the rss feed afterwards.
It's that newslist I have worked out from and there was an image intergrated if one was picked. You could compare with it and see if something is missing?
Featured article in newsList
I'm using the newsList.xslt for my news section. It has the posibility to select a featured article which always is displayed at top.
But when I haven't selected a top article, it still add the featured_news class to the first list item. This cause when I'm using paging that the latest article is shown at the top on both page 1 and 2.
You can take a look at this page: http://oldengaard.dk/da/nyheder.aspx
How could it only use the featured article if I have picked a news item?
Bjarne
Hi Bjarne
Sorry for the awfully late reply!
This is intentional, although perhaps now that you mention it is a little unintuitive (and unwanted). If this still affects you (or anyone else who might stumble onto this) you can change newslist.xslt with the following
Change (starting line 23)
To
and change (line 62)
to
Thanks for your reply ...
I have tried to change the XSLT above, but I recieve a XSLT error.
At the moment I have out commented the featured article:
Before I did that it has the featured article on top of all pages in the news list.. and when no newsitem was selected as featured, it still has added the featured class to the top newsitem, which caused that it was on all pages too in the top.
It isn't necessary in my case to have this feature, but I might need it someday.
Hi Bjarne
did you find any solution .. I am looking for the same....
Hi..
No I didn't find the solution I was looking for... but it wasn't a must for me having the featured article in the news list.. so I decided to out comment that part:
Otherwise I had the featured article on all pages in top of page. And when no featured article was selected it still added a class for the top article and considered the top article on each page as a featured article.
I also changed a bit in the paging, so instead of ?page=0 , ?page=1 etc. ....... I have ?page=1 , ?page=2 etc...
Bjarne
I have posted the full XSLT for my news list here:
thank you .. i am using ur xslt... but one more problem ... i am not able to display image of news item...
I haven't used images in my news list, but you can easily add a property to your news item doc type, where you e.g. use the media picker as datatype.
Then you can add the image in the newslist xslt:
<xsl:variable name="mediaId" select="number($currentPage/newsImage)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$currentPage/newsImage != ''">
<img src="{$mediaNode/umbracoFile}" alt="{$currentPage/@nodeName}" />
</xsl:if>
</xsl:if>
Bjarne
it is showing media image node id and not image.....
The code above I use to show an image selected with a Media Picker.
The output should only be the img part.. the rest is variables to get the media id and check if an image is selected.
yes.... but I got it... but instead of image it is showing id only... why it is not showing image?
How does your code look?
and what does you get as output?
in my xslt, I have following inside <li></li>
<xsl:if test="string(current()/newsImage) != ''">
<div class="news_image">
<a title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(current()/newsImage, false() )/Image/umbracoFile" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="current()/@nodeName"/>
</xsl:attribute>
</img>
</a>
</div>
</xsl:if>
and the output is like as follows ....see red box ...I am using umbraco 4.7
Hi Hetaurhet
Are you using 4.7? If so, your code should be
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(current()/newsImage, false() )/umbracoFile" />
</xsl:attribute>
The /Image/ part was a workaround for a particular version of Umbraco (4.5.0, IIRC)
Cheers,
Dan
Yea, I don't think you should have the /Image/ part ...
It's rarely I use the Image part after umbracoFile.. I think it can be used for check if a folder contains different file types it should only get images..
and I think the current() part only can be used inside a loop.
The code a wrote earlier was just a simple way to display an image somewhere in the template.
I think you can use this code as well:
<img src="{umbraco.library:GetMedia(./newsImage, false())/umbracoFile}" />
Sometime it's easier to split the values into variables..
Bjarne
here is my full xslt for showing news ..... newsImage is media picker type... I have image type files uploaded in media ... but still not showing image
<?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:template match="/">
<xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />
<xsl:variable name="featuredArticle">
<xsl:choose>
<xsl:when test="string($currentPage/newsFeaturedArticle) != ''">
<xsl:value-of select="$currentPage/newsFeaturedArticle" />
</xsl:when>
<xsl:otherwise>
<!-- should support autofolders if we use // -->
<xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='DbfNewsItem']">
<xsl:sort select="current()/newsDate" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="current()/@id" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="recordsPerPage">
<xsl:choose>
<xsl:when test="string($currentPage/newsPerPage) != ''">
<xsl:value-of select="$currentPage/newsPerPage" />
</xsl:when>
<xsl:otherwise>10</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="pageNumber" >
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('page') <= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="numberOfRecords" select="count($currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='DbfNewsItem'])"/>
<ul class="news_list">
<!--<xsl:call-template name="featuredNewsItem">
<xsl:with-param name="selectedItem" select="$featuredArticle" />
</xsl:call-template>-->
<xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='DbfNewsItem']">
<xsl:sort select="current()/newsDate" order="descending" />
<xsl:if test="position() > $recordsPerPage * number($pageNumber - 1) and position() <= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
<li>
<xsl:if test="string(current()/newsImage) != ''">
<div class="news_image">
<a title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(current()/newsImage, false() )/umbracoFile" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="current()/@nodeName"/>
</xsl:attribute>
</img>
</a>
</div>
</xsl:if>
<div class="news_content">
<h3>
<a class="font_green" title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">
<xsl:value-of select="current()/pageHeading"/>
</a>
</h3>
<p class="news_date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsDate, 'd. MMMM yyyy')"/></p>
<p><xsl:value-of select="umbraco.library:ReplaceLineBreaks(./newsSummary)" disable-output-escaping="yes" />…</p>
<p><a title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">Read More »</a></p>
</div>
</li>
</xsl:if>
</xsl:for-each>
</ul>
<p class="paging">
<xsl:if test="$pageNumber > 1">
<a class="page" href="?page={$pageNumber -1}">Previous</a>
</xsl:if>
<xsl:call-template name="for.loop">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
<xsl:with-param name="count" select="ceiling($numberOfRecords div $recordsPerPage)"></xsl:with-param>
</xsl:call-template>
<xsl:if test="(($pageNumber) * $recordsPerPage) < ($numberOfRecords)">
<a class="page" href="?page={$pageNumber + 1}">Next</a>
</xsl:if>
</p>
</xsl:template>
<xsl:template name="for.loop">
<xsl:param name="i"/>
<xsl:param name="count"/>
<xsl:param name="page"/>
<xsl:if test="$i <= $count">
<xsl:if test="$page != $i">
<a class="page" href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i}" >
<xsl:value-of select="$i" />
</a>
</xsl:if>
<xsl:if test="$page = $i">
<span class="currentpageitem">
<xsl:value-of select="$i" />
</span>
</xsl:if>
</xsl:if>
<xsl:if test="$i <= $count">
<xsl:call-template name="for.loop">
<xsl:with-param name="i">
<xsl:value-of select="$i + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
<xsl:with-param name="page">
<xsl:value-of select="$page"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="featuredNewsItem">
<xsl:param name="selectedItem" />
<xsl:variable name="featuredItem" select="umbraco.library:GetXmlNodeById($selectedItem)" />
<li class="featured_news">
<div class="main_news_item">
<h3>
<a class="font_green" title="{$featuredItem/@nodeName}" href="{umbraco.library:NiceUrl($featuredItem/@id)}">
<xsl:value-of select="$featuredItem/pageHeading"/>
</a>
</h3>
<p class="news_date"><xsl:value-of select="umbraco.library:FormatDateTime($featuredItem/newsDate, 'd. MMMM yyyy')"/></p>
<p><xsl:value-of select="umbraco.library:ReplaceLineBreaks($featuredItem/newsSummary)" disable-output-escaping="yes" />...</p>
<p><a class="font_green" title="{$featuredItem/@nodeName}" href="{umbraco.library:NiceUrl($featuredItem/@id)}">Read More »</a></p>
</div>
</li>
</xsl:template>
</xsl:stylesheet>
What do you got as output? Do you got the img tag in output.. or is it just the img src that is wrong?
Does it make a difference to replace current()newsImage with ./newsImage ?
i am getting following output...
and current()newsImage with ./newsImageis not making any difference ... but yes ... my xslt is not showing image... there is some problem... so is itr because of that it is not showing rss feed also?
Okay, what about the normal html code... do you got a XSLT error in frontend or? If you use Firefox and have Firebug installed you can see what you have in the code.. Safari and Chrome have a similar tool.
If you want to set up a rss feed for the newlist I think you should create a xslt file for the rss, where it has the values from the news items... and a xslt file for the normal newslist.
Is the newslist working on one of the pages? Then you always can create the rss feed afterwards.
newslist is working fine ... but only instead image it shows image id (using media ) ..... so is that a problem?
From the screenshot you got the id.. but what do you get in the code as output? Doesn't write the img tag .. <img src="..." alt="" />
Is something written inside the src attribute?
i have in my xslt as follows ....
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(current()/newsImage, false() )/Image/umbracoFile" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="current()/@nodeName"/>
</xsl:attribute>
</img>
Okay, but that is in your xslt.. what do you have in your html code as output?
You get the media id, but what else? Isn't the img tag written? If the image was inserted correctly you should get something like in the image below:
Don't you get anything inside the src attribute?
And I think you should remove the /Image part before umbracoFile..
yes I have tried removing /Image part before umbracoFile.. still it is not working ...
and what I get is ... just a number ... 1507 not even img tag
Weird that you don't get the img tag..
What if you remove the test? or instead of <xsl:if test="string(current()/newsImage) != ''"> use: <xsl:if test="string(./newsImage) != "">
Or you could take a look at the newslist from Business Website Starter Pack: http://our.umbraco.org/projects/starter-kits/business-website-starter-pack
It's that newslist I have worked out from and there was an image intergrated if one was picked. You could compare with it and see if something is missing?
hey thanks .... <xsl:if test="string(./newsImage) != ""> .. this worked out....
Great.. I'm glad you got it working... :)
is working on a reply...