Copied to clipboard

Flag this post as spam?

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


  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 15:25
    Daniel Horn
    0

    Display latest news

    Hi,

    I've got two types of news "news" and "press" but they are of the same document type.

    Home

    - Press

    -- press1

    -- press2

    - News

    -- News1

    -- News2

     

    In this document type I have a Date picker (newsDate) where I choose the date of the news or press - how do i create a macro that displays the latest news or press?

     

  • Bogdan 250 posts 427 karma points
    Mar 24, 2010 @ 15:40
    Bogdan
    0

    You make two xslt macros, with one that selects the press nodes, one that selects the news nodes.

    <xsl:variable name="pressNodes" select="umbraco.library:GetXmlNodeById(PRESS_ID)/node [string(data [@alias='umbracoNaviHide']) != '1']"/>

    <xsl:for-each select="$pressNodes">

    <xsl:sort select="data[@alias = 'newsDate']"/>

    <!-- do stuff here -->

    </xsl:for-each>

    replace PRESS_ID with the your node id. I didn't test this, and never used xsl:sort with a date, but I think this is a start.

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Mar 24, 2010 @ 15:43
    Rasmus Berntsen
    0

    If you want to list the news/press items on your "home" node, you could do something like this:

      <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
        <xsl:sort select="data[@alias='newsDate']" order="descending" />
        <xsl:if test="position() &lt;= 5">
          <xsl:value-of select="@nodeName" />
        </xsl:if>
      </xsl:for-each>

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 15:55
    Daniel Horn
    0

    I want on my Home node to show the news header, intro, a read more link, a link to the comments and the date..

    I tried yours Berntsen, it gives me the titles/nodenames of the news.

    You can see what i want here:

    http://www.sprogkernen.dk/

    It the two in the bottom i need to do, but im getting a little lost.

  • Bogdan 250 posts 427 karma points
    Mar 24, 2010 @ 16:05
    Bogdan
    0

    Because you have have "news" and "press" under the same Document Type, you have to separate them somehow, and one way is by the node id. A thing like <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']"> will get all the news nodes, no matter if they're under Press or News.

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Mar 24, 2010 @ 16:25
    Rasmus Berntsen
    3

    Ahh... I would create a PressArea and a NewsArea with items below and then loop the items like this:

    <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsArea']/node">

    ...

    </xsl:for-each>

    <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='PressArea']/node">

    ...

    </xsl:for-each>

    Or you could go with the "ID-solution" by bfi... :)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 24, 2010 @ 16:44
    Dirk De Grave
    0

    +1 on splitting up the doc types for news and press (alto maybe too late as it's impossible to change master doc type after creation)

     

    Cheers,

    /Dirk

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 17:12
    Daniel Horn
    0

    I'm gonna split 'em up and try to get what i want that way.

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 17:52
    Daniel Horn
    0

    What I'm not sure about is how i only show the newest NewsItem

  • Dan 1288 posts 3921 karma points c-trib
    Mar 24, 2010 @ 18:03
    Dan
    1
    <xsl:sort select="data[@alias = 'newsDate']" order="descending"/>
    <xsl:if test="position() &lt;= 1">
    ...
    </xsl: if>

    ?

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 18:18
    Daniel Horn
    0

    http://our.umbraco.org/projects/blog-4-umbraco/using-blog-4-umbraco/6652-Latest-blog-entries-on-homepage <- Found this post, guessing i can use the code from the first post.

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Mar 24, 2010 @ 19:33
    Rasmus Berntsen
    0

    Well, I would still go for two doctypes. Is it because you don't know how to write the xslt that lists "news header, intro, a read more link, a link to the comments and the date" or? :)

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 20:18
    Daniel Horn
    0

    Ive made two doctypes now.

    @Berntsen, yeah - I guess, and then i don't really know how to only show the latest one?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2010 @ 21:52
    Jan Skovgaard
    0

    Have you tried using the solution Dan is suggesting? It really should be working as far as I can tell.

    is the issue that you have the news stored in two categories but you only want to get the latest of ALL the news shown in your frontpage?

    Or am I missing something?

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 22:03
    Daniel Horn
    0

    I'm not sure how to use Dan's suggestion, I can see the same code is in the business starter package in the news section..

    I have divided the two categories into PressItems and NewsItems now, and I only need to show the latest NewsItem fx on the frontpage at www.sprogkernen.dk

    Ive been trying a lot of XSLT and it might be i'm doing to much and the solution is more simple than i think? :-)

    I haven't been working with XSLT for a long time, so, sorry for my newbieness..

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 24, 2010 @ 22:06
    Kim Andersen
    0

    Could you show us the XSLT that you are using to render your news Daniel?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2010 @ 22:13
    Jan Skovgaard
    0

    Being a newbie is nothing to appoligize for - we've all been at that stage and we are here to help! :-)

    In the following XSLT snippet I'm assuming that you have two "holder" document types, one called "PressArea" and one called "NewsArea" under, which you can create a document type called "news". I'm asuming that these two holders have been created as subnodes under your root-node, which is probably called "Home"...Like this...

    Home
     - PressArea
       - newsNode
       - newsNode
       - Etc.
     - NewsArea
       - newsNode
       - newsNode
       - Etc.

    So to loop through ALL news whether they are stored under "PressArea" or "NewsArea" you need to write the following

    <xsl:for-each select="$currentPage//node[@nodeTypeAlias = 'news']">
    <xsl:sort select="data [@alias = 'date']" order="descending" />

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

    fetch the news details in here...

    </xsl:if>

    </xsl:for-each>

    when you add the double "//" you are searching for all nodes that are of the "news" document type.

    I hope this snippet makes sense.

    /Jan

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 22:14
    Daniel Horn
    0

    Yes, it's here, but it's rather long:

    http://pastesite.com/14483

    Its from the http://our.umbraco.org/projects/business-website-starter-pack package.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2010 @ 22:17
    Jan Skovgaard
    0

    I'm guessing that the code you are refering to is the one you are using to display the news under the two news-areas?

    You need to make a macro speficically to display the latest news node on your frontpage. And for that you don't need the paging stuff that is also included in the code you are reffering to.

    /Jan

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 22:30
    Daniel Horn
    0

    Exactly Jan, I've tried to make a NewsLatest.xslt

      <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">
        <xsl:sort select="data[@alias='newsDate']" order="descending" />
        <xsl:if test="position() &lt;= 1">
          <xsl:value-of select="@nodeName" />
        </xsl:if>
      </xsl:for-each>

    My first error was that ive said 5 in the position instead of 1 - now its working, just have to get all the other information in also, I think ill figure it out.

    It was so simple that it made it difficult - thanks for helping out everyone! :-)

     

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 22:33
    Daniel Horn
    0

      <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">

    One more question, if I just want the nodes under the docType NewsArea - how do I do that?

    The document type aliases are the same under PressArea and NewsArea - called NewsItem

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2010 @ 22:46
    Jan Skovgaard
    0

    Glad to hear you got it working now :-)


    I think you could do it using the following

    <xsl:for-each select="$currentPage//node[@nodeTypeAlias = 'NewsArea']/node">stuff goes here...</xsl:for-each>

    /Jan

  • Daniel Horn 319 posts 344 karma points
    Mar 24, 2010 @ 23:28
    Daniel Horn
    0

    :-)

      <xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias='NewsItem']">

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

    They give the same result - hmm?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2010 @ 23:47
    Jan Skovgaard
    0

    hmm...Maybe I'm just tired but the sample I provided should only return the nodes, that are stored under the "NewsArea" node...But looks like I'll ned to have a look at it tomorrow...

    /Jan

  • Daniel Horn 319 posts 344 karma points
    Mar 25, 2010 @ 00:13
    Daniel Horn
    0

    I'm getting pretty tired also.

    Right now, i can't get it to show the latest news on my text template, but it works on the frontpage and the news and pressarea pages...

    Its like there is something with the path, but im just not good enought to see it.

  • Daniel Horn 319 posts 344 karma points
    Mar 25, 2010 @ 00:54
    Daniel Horn
    0

    I had to get it working, so i called the xslt master -> casey neehouse :-).

    Thanks for all your help guys!

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Mar 25, 2010 @ 05:11
    Casey Neehouse
    0

    lmao.. Thanks for the kind words.

    The answer was he needed to traverse up the tree to get the top node before searching for the news and press, as on some pages, those items were outside of the scope of descendants. 

    Thus:

    $currentPage/ancestor-or-self::node[@level='1']//node[@nodeTypeAlias='NewsItem'] 

    was the needed xpath expression.

  • Daniel Horn 319 posts 344 karma points
    Mar 25, 2010 @ 12:49
    Daniel Horn
    0

    Thanks for the followup Casey :-)

  • Sam 184 posts 209 karma points
    Apr 25, 2010 @ 14:03
    Sam
    0

    I also have to say thanks to Casey, that's exactly what I needed too for my news articles! Would display on the homepage but not on any others under the home node. Casey, your explanation was very informative and got the point across to me easily, and I'm totally new to this. Thanks :)

Please Sign in or register to post replies

Write your reply to:

Draft