Copied to clipboard

Flag this post as spam?

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


  • Daniel 22 posts 214 karma points
    May 11, 2017 @ 17:44
    Daniel
    0

    Show featured posts first.

    Is it possible to have an Umbraco property called 'featured' and then show these posts first in the List page?

    For example I've been trying to make this work:

        @if (!Model.Children.Any())
            {
                <article>No blog posts found</article>
            }
            else
            {
                foreach (var post in Model.Children<PostModel>())
                {
    
    
                    @if (post.GetPropertyValue<bool>("featuredPost", true))
                    {
                } 
             }
    

    The main idea is to have a section of featured posts and after those posts comes the rest.

    With that code I've noticed that the post I want to be featured does have the class applied to it but apparently they posts are shown by date and as a test I created the featured one first, so it is shown at the end of my list and not the top.

    Any way to make this work?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 11:27
    Alex Skrypnyk
    102

    Hi Daniel

    Try to use this code:

    @if (!Model.Children.Any())
    {
        <article>No blog posts found</article>
    }
    else
    {
        // where featuredPost == true
        foreach (var post in Model.Children<PostModel>().Where(x => x.GetPropertyValue<bool>("featuredPost", true)))
        {
    
        }
    
        // where featuredPost == false
        foreach (var post in Model.Children<PostModel>().Where(x => !x.GetPropertyValue<bool>("featuredPost", true)))
        {
    
        }
    }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 16, 2017 @ 08:53
    Alex Skrypnyk
    0

    Hi Daniel

    Did you solve this issue? Can we help you?

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft