Copied to clipboard

Flag this post as spam?

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


  • Meni 280 posts 538 karma points
    1 week ago
    Meni
    0

    V15 - Mess my home page - weird issue with getting nodes from tree

    Hi,

    In my home page I'm taking the latest nodes in the tree for each section.

    My website is a news site.

    So for example, my tree looks something like:

    Magazine

         Category 1
            2013
               news item
               news item
            2014
            ..
            2023
            2024
               news item
               news item
    

    So every time I'm adding a new item, it will automatically shows in home page for each section - like, the latest news.

    The code looks something like:

    category_3_node = Umbraco.Content(1234);     
    var category_3_pagesToList = @category_3_node.Children.Where(n => n.IsVisible());
    category_3_pagesToList = category_3_node.DescendantsOrSelf().Where(n => n.ContentType.Alias == "NewsPage");
    

    Where 1234 is the node id for each category in the tree which under I have folders for each year, then the news items.

    Until now U9 - U14 it worked well.

    Now after upgrading to U15 this code doesn't show the correct node. It doesn't shows the right new items. It suddenly shows items from 2015 for example.

    If I want to get the latest one, I need to put for each category the ID of 2024.

    But I don't want to do it, because , like what - now every year I'll have to update manually the code with the new id for the year ??

    Until now I didn't have to do it

    What have been changed in U15 that it messed my website?

    And how to fix it.

    Thanks

  • Midhun Roy 2 posts 72 karma points
    4 days ago
    Midhun Roy
    0

    Hi,

    Have you tried using OrderByDescending to sort the nodes by their created or updated date? OrderByDescending will ensure the latest nodes are listed first.

    For example:

     category_3_pagesToList = category_3_node.DescendantsOrSelf().Where(n => n.ContentType.Alias == "NewsPage").OrderByDescending(x=>x.CreateDate);
    
  • Meni 280 posts 538 karma points
    4 days ago
    Meni
    1

    Thanks,

    When I did OrderByDescending(x=>x.CreateDate) it gave me the first item in the tree (somewhere in 2013 ..),

    but somehow OrderBy(x=>x.CreateDate) works

    Thanks.

    P. S

    I thought it's Umbraco helper, apparently it just a standard command at LinQ ...

Please Sign in or register to post replies

Write your reply to:

Draft