Copied to clipboard

Flag this post as spam?

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


  • Høgni 16 posts 66 karma points
    Nov 14, 2013 @ 20:53
    Høgni
    0

    Get top 10 document type DESC

    Hi guys. Hope you can help me with this one. Bit of a noob

    I have a document type called "News". I would like to get the top 10 latest news document types in the a descending order.

    .

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 14, 2013 @ 21:25
    Dennis Aaen
    0

    Hi Høgni,

    You can do it by using XSLT or Razor.

    In XSLT you could do something like this:

    <ul>
       
    <xsl:for-each select="$currentPage/News">
           
    <xsl:if test="position() &lt;= 10">
               
    <xsl:sort select="@createDate" order="descending"/>
               
    <li>
                 
    <xsl:value-of select="./@nodeName"/>
               
    </li>
           
    </xsl:if>
       
    </xsl:for-each>
    </ul>

    Or you could do it Razor:

    And I think something like the should work for you: If your are using Razor macro scripts and Master pages, and not MVC.

    <ul>
     @foreach (var item in Model.News.Where("Visible").OrderBy("Name desc").Take(10)){
     
    <li>
     
    <ahref="@item.Url">@item.Name</a>
     
    </li>
    }
    </ul>

    I hope this can help you further.

    /Dennis

  • Høgni 16 posts 66 karma points
    Nov 14, 2013 @ 22:09
    Høgni
    0

    Hi thankyou for the answer. It was a Razor soulition i was looking for. But i cant seem to get anything form the foreach loop :/

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 14, 2013 @ 22:37
    Dennis Aaen
    100

    Hi Høgni,

    Okay here is an example of how you could do it. I have just taking it from my Umbraco certification Umbraco installation.

    So create a scripting file cshtml in with an associated Maco in the developer section, make your modifications to the code, so it fetch your document type called News. And then insert the macro in the template where all news to display

    <ul>
        @foreach (var item in Model.NewsItems.Where("Visible").OrderBy("CreateDate desc").Take(10)){
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>

    And in my case the document type is called NewsItem. This is an example should work if you not running MVC.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft