Copied to clipboard

Flag this post as spam?

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


  • Svante-J 7 posts 28 karma points
    Feb 07, 2022 @ 15:08
    Svante-J
    0

    heres a query for my blog posts (folowing umbraco turtorials with html template) @{ var selection = Umbraco.Content(Guid.Parse("8d7b4400-0402-4222-9a48-d253d71ec8be")) .ChildrenOfType("articleItem") .Where(x => x.IsVisible()) .OrderByDescending(x => x.CreateDate); } I whant to make a query that selects only the latest created element to put on top of page as a featured blogpost, and im nut shure how to render the Image from media picker. like

    @Item.Image

    Thanx in advance :) -Svante

  • Yaco Zaragoza 80 posts 334 karma points
    Mar 06, 2024 @ 17:56
    Yaco Zaragoza
    100

    You can add the Take parameter to the query so it only pulls the amount of records you desire. In this case you would add ".take(1)" at the end of your current query

    the code would look like this:

        @{ var selection = Umbraco.Content(Guid.Parse("8d7b4400-0402-4222-9a48-d253d71ec8be"))
    .ChildrenOfType("articleItem")
    .Where(x => x.IsVisible()) 
    .OrderByDescending(x => x.CreateDate)
    .Take(1);
        } 
    
Please Sign in or register to post replies

Write your reply to:

Draft