Copied to clipboard

Flag this post as spam?

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


  • lasse madsen 5 posts 95 karma points
    Sep 04, 2018 @ 13:59
    lasse madsen
    0

    Show lastest three posts

    Hi guys :-)

    I'm trying to output my blogposts from a partial view to frontpage. However i only want to show the lastest three posts.

    It seems like it should be very easy, however I cant seem to figure it out. Maybe you can help me?

    Heres my partial view code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    @{ var selection = Model.Content.Site().FirstChild("portfolio").Children() .Where(x => x.IsVisible()) .OrderBy("CreateDate desc"); }

    @foreach(var item in selection){
            <div class="flex-wrapper">
                <div class="flex-item">
                    @{
                        var postImage = item.GetPropertyValue<IPublishedContent>("specificProjectMainImage");
                        if (postImage != null)
                        {
                            <img src="@postImage.Url" style="width: 100%;" alt="@postImage.GetPropertyValue("alt")" />
                        }
                    }   
    
                </div>
             <div class="flex-item blogItemText">
                <h2>@item.GetPropertyValue("specificProjectTitle")</h2>
                <p>@item.GetPropertyValue("specificProjectTeaser")</p>
                <a href="@item.Url">Se projekt</a>
            </div>
            </div>
    }
    

    Please tell if my question is unclear to you.

    Best regards Lasse

  • Dave 27 posts 79 karma points
    Sep 04, 2018 @ 14:06
    Dave
    101

    Hi Lasse

    What about this, off the top of my head this may help, or at least point you in the right direction

    Model.Content.Site().FirstChild("Portfolio").Children.Where(x=>x.IsVisible()).OrderBy("CreateDate").Take(3)
    

    Notice the addition of .Take(3)

  • lasse madsen 5 posts 95 karma points
    Sep 05, 2018 @ 06:33
    lasse madsen
    0

    WUHUUU L1ca! It works like a dream! :-) Thank you so much!

  • Dave 27 posts 79 karma points
    Sep 05, 2018 @ 07:29
    Dave
    0

    My pleasure, happy Umbracoing!! :)

Please Sign in or register to post replies

Write your reply to:

Draft