Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi everyone,
I have a blog working with a partial view macro (taken from the standard template if I remember correctly), and I would like to see the latest 3 entries on the homepage, but I don't know, how to do this...
This is the code for the blog page:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Blog> @using ContentModels = Umbraco.Web.PublishedContentModels; @{ Layout = "master_de.cshtml"; } <section class="section align-left"> <div class="container"> @Umbraco.RenderMacro("latestBlogposts", new { numberOfPosts = Html.Raw(Umbraco.Field("noofposts").ToString()), startNodeId = Model.Content.Id }) </div> </section>
The macro code is:
@using ContentModels = Umbraco.Web.PublishedContentModels; @using Umbraco.Web; @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var startNodeId = Model.MacroParameters["startNodeId"] != null ? Model.MacroParameters["startNodeId"] : Model.Content.Id; var numberOfPosts = 100; if (Model.MacroParameters["numberOfPosts"] != null) { int.TryParse((string)Model.MacroParameters["numberOfPosts"], out numberOfPosts); } } @if (startNodeId != null) { @* Get the starting page *@ var startNode = Umbraco.TypedContent(startNodeId); var blogposts = startNode.Children.OrderByDescending(x => x.CreateDate).Take(numberOfPosts); if (blogposts.Any()) { foreach (ContentModels.Blogpost post in blogposts) { <section class="section align-center" style="padding: 40px 0 10px;"> <div class="container"> <div class="col-sm-6 align-center img-column"> @if(post.BlogImage != null){ <a href="@post.Url"><img src="@post.BlogImage.Url" /></a> } </div> <div class="col-sm-6 align-left"> <article style="max-width: 480px;"> <h5>@post.PageTitle</h5> <small class="blogpost-date">@post.UpdateDate.ToShortDateString()</small> <p>@post.Excerpt</p> <a href="@post.Url" class="btn btn-outline-clr" style="margin: 30px 0 0">Read more</a> </article> </div> </div> </section> } } }
I would be happy, if anyone could help me with that...
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
See blog entries on home page
Hi everyone,
I have a blog working with a partial view macro (taken from the standard template if I remember correctly), and I would like to see the latest 3 entries on the homepage, but I don't know, how to do this...
This is the code for the blog page:
The macro code is:
I would be happy, if anyone could help me with that...
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.