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.
I will try to help you out, but Razor is relativelynew to me,I come froma backgroundwithXSLT. But if yourcontent structureisthat you have apagewhereyourdocumenttypesbelow
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).
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.
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
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
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
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
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 :)
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.
is working on a reply...