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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 13:47
    Matt Brailsford
    0

    Hi Ivor,

    Give this a try

    <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="newsDate"  order="descending" />
       
        <xsl:if test="position() &lt;= 1 ">
      
        <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>

    Matt

  • sdfsfm 70 posts 94 karma points
    Aug 03, 2010 @ 14:06
    sdfsfm
    0

    Hi Matt,

     Thanks for that, but its still not working. I'm still getting a blank area. Just to confirm incase I'm getting this wrong (still a noob) NewsItem is the Doc type of the item i want shown on  a page.The news i want shown are in Home > News > news title .

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 14:12
    Matt Brailsford
    0

    Ahh, ok, maybe try changing your selector in your for-each to something like:

    $currentPage/ancestor-or-self::root//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']

    This should go from the current page, back down to the root, and then look for any NewItem at any level that isn't set to hide. It should then sort them by date descending, and select the top 1 (ie the latest).

    Give that a try and let me know if it works

    Matt

  • sdfsfm 70 posts 94 karma points
    Aug 03, 2010 @ 14:37
    sdfsfm
    0

    Great, Thanks Matt, That worked, now just need to hook up the featured functionality.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 14:39
    Matt Brailsford
    0

    Sweet, let me know if you have any probs

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft