Copied to clipboard

Flag this post as spam?

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


  • Fredrik 41 posts 161 karma points
    Nov 24, 2009 @ 11:33
    Fredrik
    0

    Newslist show different articles, depending on content.

    Hello!

    I am trying to figure out what would be the best way for making a newslist that show latest articles after date on different pages depending on content.
    There are going to be three categories, let's call them: Boat - Car - Plane
    I guess I will have to make some kind of tag-function?

    Setup:

    Content:
    - Home (Show five latest articles about Boat, Car and Plane)
    --Boat (Show five latest articles about Boat)
    --Car (Show five latest articles about Car)
    --Plane (Show five latest articles about Plane)
    --About us
    --Contact

    Any tip would be greatly appreciated!

    Regards,
    Fredrik

  • Len Dierickx 150 posts 92 karma points
    Nov 24, 2009 @ 11:55
    Len Dierickx
    1

    Hi Fredrik,

     

    You should make a document type for the news, lets call it "NewsItem".

    Create a datatype in teh developer section, called "Vehicle" and use the render control "Dropdownlist", database datatype "Ntext".

    Save it and then you will be able to add your categories: boat/car/plane.

    Add this datatype to your news document type and to any other document type you have and make it mandatory, if you need all of them categorized.

    After that you can access the categories with XSLT and filter on date and category, date is not done in the example below

     

     

    <xsl:param name="currentPage"/>

    <!-- category fo rhte current page-->

    <xsl:variable name="currentPageCat" select="$currentPage/data[@alias = 'Vehicle']"/>

    <!-- HomePage : change your doc type -->

    <xsl:variable name="source" select="$currentPage/ancestor-or-self::node[@nodeTypeAlias = 'HomePage']/@id"/>

    <xsl:template match="/">

    <ul>

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)//node[nodeTypeAlias = 'NewsItem'][string(data[@alias = 'Vehicle']) = $currentPageCat]">

    <xsl:sort select="substring(@createDate, 1, 4)" order="descending"/>

    <xsl:sort select="substring(@createDate, 6, 2)" order="descending"/>

    <xsl:sort select="substring(@createDate, 9, 2)" order="descending"/>

    <xsl:sort select="substring(@createDate, 12, 2)" order="descending"/>

    <xsl:sort select="substring(@createDate, 15, 2)" order="descending"/>

    <xsl:sort select="substring(@createDate, 18, 2)" order="descending"/>

    <li><value-of select="@nodeName"/></li>

    </xsl:for-each>

    </ul>

    <!-- start writing XSLT -->

    </xsl:template>

    </xsl:stylesheet>

     

     

    hope this helps

    Len. 

  • Finn 86 posts 50 karma points
    Nov 24, 2009 @ 13:51
    Finn
    1

    Hi Fredrik

    My solution would be to have the Plane, Boat and Car in different folders. It makes sense to make news for cars under a folder named Cars, and so on…

    All newsitems are created based on the same documenttype like newsItem or whatever…

    Then it’s easy to show newsitems for the specific folder and to show newsitems on the frontpage where the news are gathered from all newsitems regardless position in the structure.

    This will honor you structure and doesn’t require the user to make a selection of Car, Plane or Boat.

    On the Home page you can do some xslt like this (from the top of my head):

    <xsl:variable name="documentTypeAlias" select="string('newsItem')"/>
    <xsl:variable name="numberOfItems" select="5"/>


    <xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [@nodeTypeAlias=$documentTypeAlias]">

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

    And for the subfolders try something like:

    <xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias=$documentTypeAlias]">

    Hope it gets you going

    /Finn

  • Fredrik 41 posts 161 karma points
    Nov 24, 2009 @ 14:27
    Fredrik
    0

    Thanks alot to both of you!!

     Have to try both solutions out tonight when I got time. I do like the idea of not having my client to choose each time what category they want it in, even thou that's not work at all.

    I'll come back to you guys later, and again thanks for the help!

     

    Regards,
    Fredrik

     

  • Fredrik 41 posts 161 karma points
    Nov 24, 2009 @ 15:08
    Fredrik
    0

    To bad I can't put solve on both of you, but I went with Finn's way in the end!
    Thanks for the help guys!

    Regards,
    Fredrik

Please Sign in or register to post replies

Write your reply to:

Draft