Copied to clipboard

Flag this post as spam?

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


  • jefferycxl 35 posts 83 karma points
    Nov 23, 2009 @ 06:09
    jefferycxl
    0

    Get the last posted article

    Hi guys and girls

    I want to write a piece of xslt code to retrieve the data of the last artilcle that published. Any help is appreciated.

  • Gary 20 posts 44 karma points
    Nov 23, 2009 @ 07:16
    Gary
    0

    Hi Jeffery,

    Do you want the last published article as per Umbraco or the latest new article that was published? Eg if I have an article that is 2 years old and I for some reason edit it (maybe a spelling mistake) and save and publish, then this will be the last article that's published.

    Realistically though I wouldn't know why you'd want that. Assuming it's for the last created article, each node has a createDate property. You can use the XSLT and grab all the documents and order them by date in reverse and then chose the first document. (incidentally, you could possibly use the updateDate to do the other option).

    I personally prefer adding a date parameter in the docType so I can set the date manually. Sometimes articles aren't added in the correct order so you can use this field to make sure the latest article is in face the most recent one if for some reason the order of the articles published is not correct.

  • Martin Ågren 7 posts 26 karma points
    Nov 23, 2009 @ 08:52
    Martin Ă…gren
    0

    Hi i maybe you can use this the source variable is the homepage and i take only one dokument type:

     

    <xsl:variable name="source" select="1062"/>

    <xsl:template match="/">


    <ol>

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/descendant::node [string(data [@alias='umbracoNaviHide']) != '1'][@nodeTypeAlias = 'AOB-Contents Page']">

    <xsl:sort select="@createDate" order="descending" />

    <xsl:if test="position() &lt; 1">

    <li>


    <xsl:value-of select="@nodeName"/>

    </a>

    </li>

    </xsl:if>

    </xsl:for-each>

    </ol>

     

    Br

     

    Martin

  • jefferycxl 35 posts 83 karma points
    Nov 24, 2009 @ 08:52
    jefferycxl
    0

    Thank you Gary, yes I want to retrieved the last created article. 

    Thanks Martin, your code works beautifully, I implement it and it is now running on my website.

    Cheers guys

     

     

Please Sign in or register to post replies

Write your reply to:

Draft