Copied to clipboard

Flag this post as spam?

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


  • sdfsfm 70 posts 94 karma points
    Aug 03, 2010 @ 13:35
    sdfsfm
    0

    get featured news item or default to latest item

    Hi I'm trying to show the lastest news item [doctype NewsItem] on all pages, but its currently not working and if possible show a featured news item is the they dont want the lastest..

     

    my code looks like this

    <xsl:param name="currentPage"/>
    <xsl:variable name="documentTypeAlias" select="string('NewsItem')"/>
        
    <xsl:template match="/">
     
      <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
        
      <xsl:sort select="current()/data[@alias='newsItem']"  order="descending" />
        
        <xsl:if test="position() &lt;= 1 ">
      
     <xsl:value-of select="./data [@alias = 'NewsItem']"  disable-output-escaping="yes"  />

        <h2><a href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/></a></h2>
        <p class="date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsDate, 'd MMMM, yyyy')"/></p>
        <p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./newsBodyText), 100,'...')"  /></p>
        <p class="bg-btnGreen"><a href="{umbraco.library:NiceUrl(@id)}" title="" class="btn btnGreen">Continue reading</a></p>  
      
    </xsl:if>
        

    </xsl:for-each>

    Every section i have this marco on is blank

  • Sascha Wolter 615 posts 1101 karma points
    Aug 03, 2010 @ 14:11
    Sascha Wolter
    0

    Hi Ivor,

    try the following:

    instead of

    <xsl:sort select="current()/data[@alias='newsItem']"  order="descending" />

    use

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

    That orders the news items by their creation date in descending order.

    Then use position() = 1 in your test, the index starts at 1 (and not 0, so <1 will never be true).

    Instead of

    <xsl:value-of select="./data [@alias = 'NewsItem']"  disable-output-escaping="yes"  />

    you should use

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

    to get the name of the node in Umbraco.

    You can use

    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">

    only if all the news items are actually below the node that you are using this script on. If they are not you should probably introduce some variable like this: <xsl:variable name="newsItemsRoot" value="umbraco.library:GetXmlNodeById(your-root-node-id)" />, then you can use

    <xsl:for-each select="$newsItemsRoot/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">

    to get a list of all news items.

    If your client wants a favourite news item to be shown you need to wrap this with a choose statement, check if a fav news item is set and if so use that instead.

    Hope that helps,

    Sascha

  • sdfsfm 70 posts 94 karma points
    Aug 03, 2010 @ 15:26
    sdfsfm
    0

    Hi Sacha, for some weird reason my posts was duplicated. Matt Brailsofrd help me with my problem in the other post

  • Sascha Wolter 615 posts 1101 karma points
    Aug 03, 2010 @ 15:41
    Sascha Wolter
    0

    No worries, I've seen that 10 seconds after I posted this. ;)

Please Sign in or register to post replies

Write your reply to:

Draft