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
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/100581-featured-image-in-blog-overview