I've got two types of news "news" and "press" but they are of the same document type.
Home
- Press
-- press1
-- press2
- News
-- News1
-- News2
In this document type I have a Date picker (newsDate) where I choose the date of the news or press - how do i create a macro that displays the latest news or press?
Because you have have "news" and "press" under the same Document Type, you have to separate them somehow, and one way is by the node id. A thing like <xsl:for-each select="$currentPage/descendant-or-self::node
[@nodeTypeAlias='NewsItem']"> will get all the news nodes, no matter if they're under Press or News.
Well, I would still go for two doctypes. Is it because you don't know how to write the xslt that lists "news header, intro, a read more link, a link to the comments and the
date" or? :)
I'm not sure how to use Dan's suggestion, I can see the same code is in the business starter package in the news section..
I have divided the two categories into PressItems and NewsItems now, and I only need to show the latest NewsItem fx on the frontpage at www.sprogkernen.dk
Ive been trying a lot of XSLT and it might be i'm doing to much and the solution is more simple than i think? :-)
I haven't been working with XSLT for a long time, so, sorry for my newbieness..
Being a newbie is nothing to appoligize for - we've all been at that stage and we are here to help! :-)
In the following XSLT snippet I'm assuming that you have two "holder" document types, one called "PressArea" and one called "NewsArea" under, which you can create a document type called "news". I'm asuming that these two holders have been created as subnodes under your root-node, which is probably called "Home"...Like this...
Home - PressArea - newsNode - newsNode - Etc. - NewsArea - newsNode - newsNode - Etc.
So to loop through ALL news whether they are stored under "PressArea" or "NewsArea" you need to write the following
I'm guessing that the code you are refering to is the one you are using to display the news under the two news-areas?
You need to make a macro speficically to display the latest news node on your frontpage. And for that you don't need the paging stuff that is also included in the code you are reffering to.
My first error was that ive said 5 in the position instead of 1 - now its working, just have to get all the other information in also, I think ill figure it out.
It was so simple that it made it difficult - thanks for helping out everyone! :-)
hmm...Maybe I'm just tired but the sample I provided should only return the nodes, that are stored under the "NewsArea" node...But looks like I'll ned to have a look at it tomorrow...
The answer was he needed to traverse up the tree to get the top node before searching for the news and press, as on some pages, those items were outside of the scope of descendants.
I also have to say thanks to Casey, that's exactly what I needed too for my news articles! Would display on the homepage but not on any others under the home node. Casey, your explanation was very informative and got the point across to me easily, and I'm totally new to this. Thanks :)
Display latest news
Hi,
I've got two types of news "news" and "press" but they are of the same document type.
Home
- Press
-- press1
-- press2
- News
-- News1
-- News2
In this document type I have a Date picker (newsDate) where I choose the date of the news or press - how do i create a macro that displays the latest news or press?
You make two xslt macros, with one that selects the press nodes, one that selects the news nodes.
<xsl:variable name="pressNodes" select="umbraco.library:GetXmlNodeById(PRESS_ID)/node [string(data [@alias='umbracoNaviHide']) != '1']"/>
<xsl:for-each select="$pressNodes">
<xsl:sort select="data[@alias = 'newsDate']"/>
<!-- do stuff here -->
</xsl:for-each>
replace PRESS_ID with the your node id. I didn't test this, and never used xsl:sort with a date, but I think this is a start.
If you want to list the news/press items on your "home" node, you could do something like this:
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
<xsl:sort select="data[@alias='newsDate']" order="descending" />
<xsl:if test="position() <= 5">
<xsl:value-of select="@nodeName" />
</xsl:if>
</xsl:for-each>
I want on my Home node to show the news header, intro, a read more link, a link to the comments and the date..
I tried yours Berntsen, it gives me the titles/nodenames of the news.
You can see what i want here:
http://www.sprogkernen.dk/
It the two in the bottom i need to do, but im getting a little lost.
Because you have have "news" and "press" under the same Document Type, you have to separate them somehow, and one way is by the node id. A thing like <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']"> will get all the news nodes, no matter if they're under Press or News.
Ahh... I would create a PressArea and a NewsArea with items below and then loop the items like this:
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsArea']/node">
...
</xsl:for-each>
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='PressArea']/node">
...
</xsl:for-each>
Or you could go with the "ID-solution" by bfi... :)
+1 on splitting up the doc types for news and press (alto maybe too late as it's impossible to change master doc type after creation)
Cheers,
/Dirk
I'm gonna split 'em up and try to get what i want that way.
What I'm not sure about is how i only show the newest NewsItem
?
http://our.umbraco.org/projects/blog-4-umbraco/using-blog-4-umbraco/6652-Latest-blog-entries-on-homepage <- Found this post, guessing i can use the code from the first post.
Well, I would still go for two doctypes. Is it because you don't know how to write the xslt that lists "news header, intro, a read more link, a link to the comments and the date" or? :)
Ive made two doctypes now.
@Berntsen, yeah - I guess, and then i don't really know how to only show the latest one?
Have you tried using the solution Dan is suggesting? It really should be working as far as I can tell.
is the issue that you have the news stored in two categories but you only want to get the latest of ALL the news shown in your frontpage?
Or am I missing something?
I'm not sure how to use Dan's suggestion, I can see the same code is in the business starter package in the news section..
I have divided the two categories into PressItems and NewsItems now, and I only need to show the latest NewsItem fx on the frontpage at www.sprogkernen.dk
Ive been trying a lot of XSLT and it might be i'm doing to much and the solution is more simple than i think? :-)
I haven't been working with XSLT for a long time, so, sorry for my newbieness..
Could you show us the XSLT that you are using to render your news Daniel?
Being a newbie is nothing to appoligize for - we've all been at that stage and we are here to help! :-)
In the following XSLT snippet I'm assuming that you have two "holder" document types, one called "PressArea" and one called "NewsArea" under, which you can create a document type called "news". I'm asuming that these two holders have been created as subnodes under your root-node, which is probably called "Home"...Like this...
Home
- PressArea
- newsNode
- newsNode
- Etc.
- NewsArea
- newsNode
- newsNode
- Etc.
So to loop through ALL news whether they are stored under "PressArea" or "NewsArea" you need to write the following
<xsl:for-each select="$currentPage//node[@nodeTypeAlias = 'news']">
<xsl:sort select="data [@alias = 'date']" order="descending" />
<xsl:if test="position() <=1">
fetch the news details in here...
</xsl:if>
</xsl:for-each>
when you add the double "//" you are searching for all nodes that are of the "news" document type.
I hope this snippet makes sense.
/Jan
Yes, it's here, but it's rather long:
http://pastesite.com/14483
Its from the http://our.umbraco.org/projects/business-website-starter-pack package.
I'm guessing that the code you are refering to is the one you are using to display the news under the two news-areas?
You need to make a macro speficically to display the latest news node on your frontpage. And for that you don't need the paging stuff that is also included in the code you are reffering to.
/Jan
Exactly Jan, I've tried to make a NewsLatest.xslt
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
<xsl:sort select="data[@alias='newsDate']" order="descending" />
<xsl:if test="position() <= 1">
<xsl:value-of select="@nodeName" />
</xsl:if>
</xsl:for-each>
My first error was that ive said 5 in the position instead of 1 - now its working, just have to get all the other information in also, I think ill figure it out.
It was so simple that it made it difficult - thanks for helping out everyone! :-)
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
One more question, if I just want the nodes under the docType NewsArea - how do I do that?
The document type aliases are the same under PressArea and NewsArea - called NewsItem
Glad to hear you got it working now :-)
I think you could do it using the following
<xsl:for-each select="$currentPage//node[@nodeTypeAlias = 'NewsArea']/node">stuff goes here...</xsl:for-each>
/Jan
:-)
<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
<xsl:for-each select="$currentPage//node[@nodeTypeAlias = 'NewsArea']/node">
They give the same result - hmm?
hmm...Maybe I'm just tired but the sample I provided should only return the nodes, that are stored under the "NewsArea" node...But looks like I'll ned to have a look at it tomorrow...
/Jan
I'm getting pretty tired also.
Right now, i can't get it to show the latest news on my text template, but it works on the frontpage and the news and pressarea pages...
Its like there is something with the path, but im just not good enought to see it.
I had to get it working, so i called the xslt master -> casey neehouse :-).
Thanks for all your help guys!
lmao.. Thanks for the kind words.
The answer was he needed to traverse up the tree to get the top node before searching for the news and press, as on some pages, those items were outside of the scope of descendants.
Thus:
was the needed xpath expression.
Thanks for the followup Casey :-)
I also have to say thanks to Casey, that's exactly what I needed too for my news articles! Would display on the homepage but not on any others under the home node. Casey, your explanation was very informative and got the point across to me easily, and I'm totally new to this. Thanks :)
is working on a reply...