Copied to clipboard

Flag this post as spam?

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


  • Frederik T 242 posts 373 karma points
    Jul 15, 2020 @ 14:40
    Frederik T
    0

    Displaying information for "next" and "previous" blog post, can it be done better?

    I am creating a custom blog theme, and in a blog post, links for the next and previous blog posts are shown at the bottom. It was a bit fiddly to get it to work but it is working as intended now. To get it to work I changed the view model from Articulate.Models.PostModel to Umbraco.Web.Mvc.UmbracoViewPage<Articulate.Models.PostModel>

    Though I can't shake the feeling that it can be done more "correct" so to speak, for example I really want to get the next blog post as an articulate blog post object, so I have access to the Author objects and so on. Can this be made better?

    @{
        var next = Model.Next();
        var prev = Model.Previous();
    }
    <nav class="post-navigation">
        <h2 class="screen-reader-text">Post navigation</h2>
        @if (next != null)
        {
            var nextImg = next.GetProperty("postImage").GetValue() as Umbraco.Core.PropertyEditors.ValueConverters.ImageCropperValue;
            var nextAuthor = next.GetProperty("author").GetValue() as string;
            <div class="nav-next">
                <div class="nav-inside">
                    <div class="nav-before">Next</div>
                    <h3 class="nav-title"><a href="@next.Url">@next.Name</a></h3>
                    @if (!string.IsNullOrWhiteSpace(nextAuthor))
                    {
                        <div class="nav-meta">
                            <span class="sep">By</span> @nextAuthor <span class="sep">on</span> <time class="published" datetime="@next.UpdateDate.ToString("yyyy-MM-dd")">@next.UpdateDate.ToString("D", System.Globalization.CultureInfo.CreateSpecificCulture(Culture))</time>
                        </div>
                    }
                </div>
                @if (nextImg != null)
                {
                    var thumbnail = Url.GetCropUrl(nextImg, cropAlias: "blogPost", useCropDimensions: true, htmlEncode: false, upScale: false);
                    <a href="@next.Url" class="nav-thumb"><img src="@thumbnail" alt="@next.Name" /></a>
                }
            </div>
        }
        @if (prev != null)
        {
            var prevImg = prev.GetProperty("postImage").GetValue() as Umbraco.Core.PropertyEditors.ValueConverters.ImageCropperValue;
            var prevAuthor = prev.GetProperty("author").GetValue() as string;
            <div class="nav-previous">
                <div class="nav-inside">
                    <div class="nav-before">Previous</div>
                    <h3 class="nav-title"><a href="@prev.Url">@prev.Name</a></h3>
                    @if (!string.IsNullOrWhiteSpace(prevAuthor))
                    {
                        <div class="nav-meta">
                            <span class="sep">By</span> @prevAuthor <span class="sep">on</span> <time class="published" datetime="@prev.UpdateDate.ToString("yyyy-MM-dd")">@prev.UpdateDate.ToString("D", System.Globalization.CultureInfo.CreateSpecificCulture(Culture))</time>
                        </div>
                    }
    
                </div>
                @if (prevImg != null)
                {
                    var thumbnail = Url.GetCropUrl(prevImg, cropAlias: "blogPost", useCropDimensions: true, htmlEncode: false, upScale: false);
                    <a href="@prev.Url" class="nav-thumb"><img src="@thumbnail" alt="@prev.Name" /></a>
                }
            </div>
        }
    </nav>
    
  • 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.

Please Sign in or register to post replies