I am making a website with a newspage on it. It uses a macro to display all the newspages created under it.
I would like to make something that i can use on all the other pages that also shows the 3 latest news created. Can it be made with a macro and then insert that macro in the template on the other pages? Hope it makes sense.
What you are trying to do, I’ve done over and over and over…
List the news items under current (doc type alias newsItem). The list use paging with 25 items per page and only show news with news date lower than or equal to right now:
I have tried both Tim and Fdo's examples without luck. I don't know what I am doing wrong, mabye some of the alias's ?
I Tim's example umbraco won't let me save the xslt file, because of errors. I only change the ‘NewsPage’ to my own in your examples. Is that correct?
And in the last example code from Fdo i dosen't display anything when i put the macro in my template. Not sure if i am changing the right alias's. Can you point out if i need to change more then the following line?
The example expects a document type property newsDate as date and time picker to hold the date and time of the news item. With news items I never use create date or update date, but you can try and replace with one of these properties.
I also have others properties like newsHeader and newsResume, both textstrings, but you can just replace them with you own property like bodyText or remove them from the xslt.
There are two variables you can change:
To test if there is any news items to show at all, try this, where I changed the for-each and sort statement and used the create date and node name for output (typed directly into the forum, haven’t tested the code):
No matter where in your site structure you create a page based on the documenttype newsItem, it will appear in the list - if the conditions in the for-each is meet. In the example the only condition required is the documenttype newsItem!
So if you got a news item that doesn’t appear. Then it isn’t based on newsItem.
Ahhh now i see why i have problems! I have a document-type for my newspage and another one for all my childpages. Thought it would ignore that and take the subpages anyway. But i guess it's because its looks at the doc-type alias. Total newbie i know:P
Can anyone spot why this code isn't working? I am using the latest version of umbraco. It saved without any errors but when I load the page (macro on template) nothing... :(
Making a newslist
Hi
I am new to umbraco and .xslt, and need som help.
I am making a website with a newspage on it. It uses a macro to display all the newspages created under it.
I would like to make something that i can use on all the other pages that also shows the 3 latest news created. Can it be made with a macro and then insert that macro in the template on the other pages? Hope it makes sense.
Any help would be greatly appreciated, thanks;)
Comment author was deleted
Sure that's possible.
Check out this example: http://www.nibble.be/?p=15
Comment author was deleted
I guess in order to be able to work on each page you need something like
$currentPage/ancestor-or-self::node [@level = 1]/descendant::node [@nodeTypeAlias = ‘NewsPage’]/node
Hi MichaelHHDK,
...And you'll need some sorting mechanism which is also available out-of-the-box in xslt
[code][/code]
More questions. Feel free to ask..
Regards,
/Dirk
Hi Michael
What you are trying to do, I’ve done over and over and over…
List the news items under current (doc type alias newsItem). The list use paging with 25 items per page and only show news with news date lower than or equal to right now:
[b]-News archive
--News 1
--News 2
--News 3[/b]
[code]
]>
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">
[/code]
If you got news items in archives like per year, this XSLT lists the latest 25 items on archive main page.
[b]-News archive (Archive main page)
--2007
---News 1
---News 2
--2008
---News 1
---News 2
--2009
---News 1
---News 2[/b]
The page only show news with news date lower than or equal to right now:
[code]
]>
<>
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">
[/code]
If you want to show x number of news items on the front page (or on any page for that matter):
[b]Front page
-Section page
--News archive
---2008
----News 1
----News 2
---2009
----News 1
----News 2[/b]
[code]
]>
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">
[/code]
Hope it helps you and others with same challenge.
/Finn
Hi guys
Thx for all the help:) Gonna get working on it right away.
Michael
Hi again guys
I have tried both Tim and Fdo's examples without luck. I don't know what I am doing wrong, mabye some of the alias's ?
I Tim's example umbraco won't let me save the xslt file, because of errors. I only change the ‘NewsPage’ to my own in your examples. Is that correct?
And in the last example code from Fdo i dosen't display anything when i put the macro in my template. Not sure if i am changing the right alias's. Can you point out if i need to change more then the following line?
The example expects a document type property newsDate as date and time picker to hold the date and time of the news item. With news items I never use create date or update date, but you can try and replace with one of these properties.
I also have others properties like newsHeader and newsResume, both textstrings, but you can just replace them with you own property like bodyText or remove them from the xslt.
There are two variables you can change:
To test if there is any news items to show at all, try this, where I changed the for-each and sort statement and used the create date and node name for output (typed directly into the forum, haven’t tested the code):
[code]
]>
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">
[/code]
Thanks again for the help and patience with this newbie:)
Hi Finn
Your latest code works. It shows the latest date for created news and the name of my news page.
I would like it to go 1 level deeper and get the 3 latest created pages under my newspage(their title and link directly to them). Is that possible?
Michael
Hi Michael,
It should there already:
[code]
Dirk is totally right.
No matter where in your site structure you create a page based on the documenttype newsItem, it will appear in the list - if the conditions in the for-each is meet. In the example the only condition required is the documenttype newsItem!
So if you got a news item that doesn’t appear. Then it isn’t based on newsItem.
/Finn
Ahhh now i see why i have problems! I have a document-type for my newspage and another one for all my childpages. Thought it would ignore that and take the subpages anyway. But i guess it's because its looks at the doc-type alias. Total newbie i know:P
Thank you all for for all the help:)
Michael
Can anyone spot why this code isn't working? I am using the latest version of umbraco. It saved without any errors but when I load the page (macro on template) nothing... :(
[code]
]>
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">
[/code]
[code]
Thanks fdo... Spot on.
is working on a reply...