Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Apr 26, 2013 @ 17:59
    Craig O'Mahony
    0

    Listing top 5 content nodes by number

    Hi,

    Not sure exactly where to post this (its more of a general programming question).

    I have a load of content that's all of the same document type with contains a custom field called weight. Each document in the content tree gets given a weight (a number) which can be altered the same as any other content item. What I'm trying to do is pull the top 10 documents (the higher the weight the more important they are) and display them as a list of hot topics. 

    And to be honest I'm not sure where to start!

    Can anybody help?

    Thanks,

    Craig

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 26, 2013 @ 19:24
    Dennis Aaen
    2

    Hi Graig,

    I will try to help you out, but Razor is relatively new to me, I come from a background with XSLT. But if your content structure is that you have a page where your document types below

    I think you could do something like this.

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

    In my example I get a list out based on the document type by the alias newsItem. Hope my example can help you or inspire you to a solution.

    /Dennis

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 01, 2013 @ 11:33
    Dennis Aaen
    0

    Hi Craig,

    I just want to hear if you managed to find a solution, to your problem, or you still need some help, to solve your question.

    /Dennis

  • Craig O'Mahony 364 posts 918 karma points
    May 01, 2013 @ 19:59
    Craig O'Mahony
    0

    Hi Darren,

    I did indeed manage to get it sorted by using the xslt order by property and then checking thru the position of the node that I'm working with. I'll post up the code if you like (I'm at home at the min so I'll do that in the morning if you want to see).

    Thanks,

    Craig

  • Charles Afford 1163 posts 1709 karma points
    May 06, 2013 @ 18:26
    Charles Afford
    0

    hi, are you using any server side code?  Or is this client side.  So as i understand it you need the numeric values from properties and then  you want to select the nodes with the highest number from these properties?.

    So what you might want to do is use List something like (POP PUSH) i think its called 

    //

    //foreach node

    //get the property value

    //If the list.length < 10 then add the node

    //if  > 10 then sort the list by descending and if the last value in the list is less than the current value then add it.

    //Otherwise its not in the top ten  so dont add it.

    Something like this.

    If you need some more help just ask :) Charlie :)

     

  • Craig O'Mahony 364 posts 918 karma points
    May 08, 2013 @ 15:55
    Craig O'Mahony
    100

    If Charlie,

    I managed to get it sorted in XSLT in the end.

    <xsl:for-each select="$homeNode/Blog/DateFolder/DateFolder/DateFolder/BlogPost">

    <xsl:sort select="pageViews" data-type="number" order="descending" />

    <xsl:choose>

    <xsl:when test="position() > 3">

    <!--No Nothing-->

    </xsl:when>

    <xsl:otherwise>

    <!--

    <xsl:value-of select="@nodeName" /> -

    <xsl:value-of select="./pageViews" /><br/>

    -->

    <li class="cat-item">

    <a href="{umbraco.library:NiceUrl(@id)}">

                 <xsl:value-of select="@nodeName"/>

    <!--<xsl:value-of select="./pageViews" />-->

    </a>

    </li>

    </xsl:otherwise>

    </xsl:choose>

     

    </xsl:for-each>

    That sorted the baby!!!

    Thanks.

     

Please Sign in or register to post replies

Write your reply to:

Draft