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'm trying to set up a blog, and the individual post is working already, but I don't manage to get the image into the blogoverview.
I use a partial macro file, and this would be my code:
@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 = 3; if (Model.MacroParameters["numberOfPosts"] != null) { int.TryParse((string)Model.MacroParameters["numberOfPosts"], out numberOfPosts); } } @if (startNodeId != null) { var startNode = Umbraco.TypedContent(startNodeId); var blogposts = startNode.Children.OrderByDescending(x => x.CreateDate).Take(numberOfPosts); if (blogposts.Any()) { <div class="blogposts"> @foreach (ContentModels.Blogpost post in blogposts) { <a href="@post.Url"> <h5 class="heading-alt">@post.PageTitle</h5> <div class="blogpost-meta"> <small class="blogpost-date">@post.CreateDate.ToShortDateString()</small> </div> <div class="blogpost-excerpt">@post.Excerpt</div> <img src="@post.GetPropertyValue("BlogImage")" /> </a> } </div> }
This is the closest I could get. With this code I at least see an unloaded image with the URL "".
I would be happy, if anyone could help me to get the image into the blogpost overview.
Thanks, Simeon
Hi Simeon,
Try this:
@if(post.BlogImage != null){ <img src="@post.BlogImage.Url" /> }
This should, I believe, give you your image. (Making the assumption that BlogImage property is a media picker)
Thanks
Nik
Hi Nik,
That did the trick!
Thanks a million!!
Best, Simeon
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
Featured image in blog overview
Hi everyone,
I'm trying to set up a blog, and the individual post is working already, but I don't manage to get the image into the blogoverview.
I use a partial macro file, and this would be my code:
This is the closest I could get. With this code I at least see an unloaded image with the URL "
".
I would be happy, if anyone could help me to get the image into the blogpost overview.
Thanks, Simeon
Hi Simeon,
Try this:
This should, I believe, give you your image. (Making the assumption that BlogImage property is a media picker)
Thanks
Nik
Hi Nik,
That did the trick!
Thanks a million!!
Best, Simeon
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.