Copied to clipboard

Flag this post as spam?

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


  • Riaz 5 posts 75 karma points
    Jul 04, 2018 @ 12:00
    Riaz
    0

    How to display recent posts in home page

    How to display recent posts in home page that is not a blog page. kindly support.

  • Matt 359 posts 842 karma points
    Jul 05, 2018 @ 14:31
    Matt
    0

    What do you mean by recent posts? how are these "posts" generated?

  • Riaz 5 posts 75 karma points
    Jul 05, 2018 @ 20:19
    Riaz
    0

    for example, just using smart-blog plugin, we are displaying all the posts in the blog page in a recently published order. In the same we want to display the short content of recently published 3 or 4 posts in the home page of the website (means not in the blog page). please check this link for reference for the blog page : http://constro-umbraco.potenzaglobalsolutions.com/blog/blog-classic/right-sidebar/

  • Matt 359 posts 842 karma points
    Jul 05, 2018 @ 22:05
    Matt
    0

    You could create a partial view, I did this with 1 of my websites. So I had the main blog page, then created a partial view for the home page which showed the 3 latest blog articles. I then could use this on other pages as well.

  • Riaz 5 posts 75 karma points
    Jul 08, 2018 @ 05:57
    Riaz
    0

    Could you please share the code and procedure the achieve the above mentioned recent posts as per your suggestion.

  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Jul 08, 2018 @ 20:02
    Owain Williams
    0

    Hi Riaz, Here is how I do it on my site - I use a partial view on the homepage which gets the latest 6 blog posts - it could be any post though.
    I also take an excert from the blog and show that on the homepage.

    It's not smart blog but I think it should still point you in the right direction hopefully. This code is actually using Articulate - another blog package.

    Hope it helps.

    O.

       @inherits UmbracoTemplatePage
    
        @{
            var blogNodes = @Model.Content.AncestorOrSelf(1).Descendants("ArticulateRichText").OrderBy("publishedDate desc").Take(6);
        }
    
    
        @foreach (var blogNode in blogNodes)
        {
            var blogTitle = @blogNode.Name;
            var tempExcerpt =  @blogNode.GetPropertyValue("excerpt").ToString();
            const int MaxLength = 90;
    
        <div class="col-md-4 col-xs-12 blogBox">
    
        <div class="image">
            @if (@blogNode.GetCropUrl("croppedImage", "thumbnail") != "")
            {
                <a href="@blogNode.Url">
                    <img src="@blogNode.GetCropUrl(" croppedImage", "thumbnail" )" alt="@blogNode.GetPropertyValue(" altText")" class="img-responsive" />
                </a>
            }
            else
            {
                <a href="@blogNode.Url">     
                    <img src="@Umbraco.Media(1925).Url" alt="A blog post" class="img-responsive" />
                </a>
            }
        </div>
        <div class="copy" style="padding: 0 5px 5px 5px;">
            <h4 class="media-heading"><a href="@blogNode.Url">@blogTitle</a></h4>
    
            @if (tempExcerpt.Length > MaxLength)
            {
                tempExcerpt = tempExcerpt.Substring(0, MaxLength)+"...";
            }
            <p>@tempExcerpt</p>
            <h6>@blogNode.GetPropertyValue("author") / @(blogNode.GetPropertyValue<DateTime>("publishedDate").ToString("dd-MM-yy")) / <a href="@blogNode.Url#disqus_thread"></a></h6>
    
            <div class="author" style="border-top: 1px solid #ccc; padding: 0 5px 5px 5px;">
            </div>
            <div class='clear'></div>
        </div>
    </div>
    }
    
  • Matt 359 posts 842 karma points
    Jul 09, 2018 @ 07:04
    Matt
    0

    Hello Riaz,

    What I would do is create a new Partial view called something like Homeblog, then using the Query builder select what data you want to get e.g

    I want to get all "Blog Comments" from "Blog"

    You can also select how you want to order it, If you want to get e.g the latest 5 comments just add the following to your selection;

    .OrderBy("CreateDate desc").Take(5)
    

    Then go to your home page template and insert the Partial view.

    @Html.Partial("Homeblog")
    

    This is how I show the latest blogs on my home page which you can adapt.

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    
        @{
            var selection = Model.Content.Site().FirstChild("blog").Children("blogItem").OrderBy("CreateDate desc").Take(3);
        }
    
            @foreach(var item in selection){
    
                          <div class="recent-blog-div">
                            <a href="@item.Url" class = "main-page-blog-title-links"><h4 class="recent-blog-title">@item.GetPropertyValue("blogPostShortTitle")</h4></a>
                            <div class="text-block-3">@Umbraco.Field(item, "updateDate", formatAsDate: true)</div>
                          </div>
    }
    
  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Jul 18, 2018 @ 16:10
    Jeppe Volander Rasmussen
    0

    How would you display the blogpost image here?

  • Matt 359 posts 842 karma points
    Jul 19, 2018 @ 07:47
    Matt
    0

    Same sort of way.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var selection = Model.Content.Site().FirstChild("blog").Children("blogItem").OrderBy("CreateDate desc").Take(1);
    }
    
    @foreach(var item in selection){
        <div class="blog-info-box">
            <a href="@item.Url" ><h3 class="blog-title">@item.Name</h3></a>
            <p class="blog-para">@item.GetPropertyValue("blogTeaser")</p>
        </div>
    
    
        var blogImage = item.GetPropertyValue<IPublishedContent>("blogImage");
        if (blogImage != null)
        {
            <img src="@blogImage.Url" height="300" width="447">
        }
    }
    
  • 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