Copied to clipboard

Flag this post as spam?

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


  • Travis Schoening 47 posts 173 karma points
    Oct 26, 2018 @ 23:39
    Travis Schoening
    0

    Ordering/Listing nodes by uIncrement value

    Is there a way to query nodes by uIncrement value? As in, listing content on the frontend by view count?

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 27, 2018 @ 16:10
    Alex Skrypnyk
    0

    Hi Travis

    If you print our uIncrement values, what is it?

    Alex

  • Cimplex 113 posts 576 karma points
    Nov 02, 2018 @ 15:30
    Cimplex
    0

    Hi Travis,

    There's currently no function for that, the values are stored in the database and not on the node so Alex approach wont work I'm afraid. A real hacky solution is something like this, but remember, each time you use the CounterService it'll create a DB request so it can be quite heavy if you have alot of nodes:

    var stats = new Dictionary<IPublishedContent, int>();
    
    foreach (var page in Model.Content.AncestorOrSelf(1).DescendantsOrSelf())
    {
        stats.Add(page, CounterService.GetValueBetween(page.Id, DateTime.Now.AddYears(-1), DateTime.Now));
    }
    
    <ul>
        @foreach (var topStats in stats.OrderByDescending(x => x.Value).Take(3))
        {
            <li>@topStats.Key.Name</li>
        }
    </ul>
    

    // Herman

Please Sign in or register to post replies

Write your reply to:

Draft