Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MichaelHHDK 6 posts 20 karma points
    Jan 29, 2009 @ 15:35
    MichaelHHDK
    0

    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

    Jan 29, 2009 @ 15:43

    Sure that's possible.

    Check out this example: http://www.nibble.be/?p=15

  • Comment author was deleted

    Jan 29, 2009 @ 15:44

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 29, 2009 @ 15:50
    Dirk De Grave
    0

    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

  • Finn 86 posts 50 karma points
    Jan 29, 2009 @ 20:41
    Finn
    0

    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

  • MichaelHHDK 6 posts 20 karma points
    Jan 30, 2009 @ 10:07
    MichaelHHDK
    0

    Hi guys

    Thx for all the help:) Gonna get working on it right away.

    Michael

  • MichaelHHDK 6 posts 20 karma points
    Jan 30, 2009 @ 11:53
    MichaelHHDK
    0

    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?

  • Finn 86 posts 50 karma points
    Jan 30, 2009 @ 12:31
    Finn
    0

    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]

  • MichaelHHDK 6 posts 20 karma points
    Jan 30, 2009 @ 12:43
    MichaelHHDK
    0

    Thanks again for the help and patience with this newbie:)

  • MichaelHHDK 6 posts 20 karma points
    Jan 30, 2009 @ 13:56
    MichaelHHDK
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 30, 2009 @ 14:18
    Dirk De Grave
    0

    Hi Michael,

    It should there already:

    [code]

  • Finn 86 posts 50 karma points
    Jan 30, 2009 @ 14:50
    Finn
    0

    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

  • MichaelHHDK 6 posts 20 karma points
    Jan 30, 2009 @ 14:53
    MichaelHHDK
    0

    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

  • NightWolf 41 posts 44 karma points
    Feb 03, 2009 @ 13:39
    NightWolf
    0

    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]

  • Finn 86 posts 50 karma points
    Feb 03, 2009 @ 13:45
    Finn
    0

    [code]

  • NightWolf 41 posts 44 karma points
    Feb 04, 2009 @ 02:24
    NightWolf
    0

    Thanks fdo... Spot on.

Please Sign in or register to post replies

Write your reply to:

Draft