Copied to clipboard

Flag this post as spam?

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


  • rs82uk 10 posts 73 karma points
    Jan 30, 2015 @ 11:31
    rs82uk
    0

    Getting latest blog posts Umbraco 7.2

    Hi Just wondering if anyone has done any work getting the latest blog posts to display on the homepage.

    Seems to be something that has been asked a few times for older versions but can't see any mention recently?

    Thanks in advance

  • rs82uk 10 posts 73 karma points
    Jan 30, 2015 @ 15:19
    rs82uk
    0

    So After quite a bit of experimentation I have accomplished this

    I created a new Macro and added two Parameters

    • NewsPicker of type Content Picker
    • NewsItems of type numeric

    Then added a new MacroPartial with the following code

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @if (Model.MacroParameters["NewsPicker"] != null)
    {
        var newsNode = Umbraco.Content(Model.MacroParameters["NewsPicker"]);
        int postLimit = Convert.ToInt32(Model.MacroParameters["NewsItems"]);
        <div class="container">
            <div class="row">
        @foreach (var post in newsNode.Children.Take(postLimit))
        {
                <div class="col-sm-6">
                    <div class="content equal">
                        <a href="@post.Url">
                            <div class="date">@post.CreateDate.ToLongDateString()</div>
                            <h2>@post.Name</h2>     
                            <p>@Umbraco.Truncate(post.Introduction, 240, true)</p>
                        </a>
                    </div>
                </div>
        }
            </div>
        </div>
    }
    

    Then in your grid you can insert a macro select your new macro and use the content picker to select your blog page obviously this will need some styling etc but should be enough to get people started. no doubt this has been documented somewhere else and I was just being dense but hopefully it helps someone.

Please Sign in or register to post replies

Write your reply to:

Draft