Copied to clipboard

Flag this post as spam?

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


  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 12:08
    Max
    0

    News filtering by News Expire date

    I have multiple news sorted by new date descending order in xslt to display the latest news at first :

     <xsl:sort select="newsDate" order="descending"/>

     

    but i dont want to display  the news which has already expired according to 'newsExpireDate'

    property

    i tried using and umbraco.library:DateGreaterThan it gave date format error

    any suggestion some xslt code samples wil be very useful

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 03, 2012 @ 12:24
    Chriztian Steinmeier
    1

    Hi Max,

    This usually happens because the property is empty (it's probably empty if an item should not expire, right?)

    You may be able to do something like this:

      <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
        <xsl:variable name="newsRoot" select="$siteRoot/NewsSection" /><!-- Select the right node here --> 
        <!-- Grab items with an expire date and make sure it is after today and combine with items that have no expire date -->
        <xsl:variable name="newsItems" select="$newsRoot//NewsItem[normalize-space(newsExpireDate)][umbraco.library:DateGreaterThanToday(newsExpireDate)] | $newsRoot//NewsItem[not(normalize-space(newsExpireDate))]" />
    
        <xsl:for-each select="$newsItems">
            <xsl:sort select="newsDate" data-type="text" order="descending" />
    
            <!-- Do something -->
    
        </xsl:for-each>
    
    EDIT: Note that I'm assuming your "News" document types are named "NewsSection" (for the container) and "NewsItem" (for the individual items) and that the News section is located as a direct child of your site's Home. All of this can be easily changed...  

    /Chriztian

  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 12:58
    Max
    0

    umbraco.library:DateGreaterThanToday giving this error :

    Error occured

    System.FormatException: String was not recognized as a valid DateTime. 
    at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) 
    at umbraco.library.DateGreaterThanToday(String firstDate)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 03, 2012 @ 13:01
    Chriztian Steinmeier
    0

    Hi Max,

    Is the newsExpireDate a "Date" or "DateTime" data type property?

    (It needs to be in the '2011-01-03T12:00:00' format)

    /Chriztian

  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 13:15
    Max
    0

    i am using Datepicker in teh document types as property ....

    hat do you suggest

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 03, 2012 @ 13:20
    Chriztian Steinmeier
    0

    OK - could you post the relevant XSLT you're using?

    Also - which version of Umbraco are you using?

    /Chriztian 

  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 13:25
    Max
    0

    i ma using umbraco version 4.7

     <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and umbraco.library:DateGreaterThanToday(newsExpireDate)] ">
        
         <xsl:sort select="newsDate" order="descending"/>
      

    //news items

     

    </xsl:for-each>

     

     

  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 13:33
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 03, 2012 @ 13:36
    Chriztian Steinmeier
    1

    Hi Max,

    The reason this fails is exactly what I wrote in the first answer: Some (or even just one) of the children of $currentPage has an empty newsExpireDate and thus, the library call fails (it's called for every node in the selection).

    That's why you should make sure the library call is only executed on nodes that have a date in that field, which is what I posted.

    Try this then instead:

    <xsl:variable name="newsItems" select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]" />
    <xsl:for-each select="$newsItems[normalize-space(newsExpireDate)][umbraco.library:DateGreaterThanToday(newsExpireDate)] | $newsItems[not(normalize-space(newsExpireDate))]">
    <xsl:sort select="newsDate" order="descending" />
        <!-- Do something -->
    </xsl:for-each>

    /Chriztian 

  • Max 144 posts 166 karma points
    Jan 03, 2012 @ 13:58
    Max
    0

    yes thanks

    /Chriztian   finally it works

    now i got it

     

Please Sign in or register to post replies

Write your reply to:

Draft