Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Feb 19, 2016 @ 15:52
    Owain Williams
    0

    Merge two lists, a fresh look at the problem

    Hi Last year I moved my site to Umbraco and used Articulate, it's been great. I looked at options back then on how to merge two lists of blogs into one stream but hit a number of issues. I'm now looking to revisit the issue and I'm looking for your help again.

    Rather than try and get my code to work I am hoping to look at a new fresh approach or use an example that someone else might have got to work.

    I've two archives so my setup looks like:

    • Home
      • -Blogs
        • Blog 1
          • Archive
            • BlogPost
        • Blog 2
          • Archive
            • BlogPost

    So I can display each individual list of blogs on the homepage without any issues. It was suggested I use a Union on the two lists but I could never get that to work.

    Looking forward to working this one out, Thanks.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Feb 23, 2016 @ 16:17
    Owain Williams
    0

    I've had some time to think about this and I think I have been approaching it all wrong. I had my template setup to pass the blog id to a partial view, the partial view then read the archive and displayed the list of posts. On the template I had 2 calls to the partial.

    What I think I need to do is rewrite my partial view. Give the partial view both blog ids, not just one, and then merge the two lists within the partial. Maybe save each list into an array and merge them by date.

    Does this make sense? Is it possible?

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Feb 24, 2016 @ 13:04
    Owain Williams
    102

    Solved it!

    On my homepage template I call a partial view, within that partial I then search for all contents of my site with a document type 'ArticulateRichText', this pulled everything I needed and then I sorted it by date. Bingo!

    Hope this helps others.

    @inherits UmbracoTemplatePage
    
    
        @{
            var blogNodes = @Model.Content.AncestorOrSelf(1).Descendants("ArticulateRichText").OrderBy("publishedDate desc").Take(5);
        }
    
    
    
    @foreach (var blogNode in blogNodes)
    {
    
    
        var blogTitle = @blogNode.Name;
    
    
        <div class="row">
            <div class="col-md-6">
        <a href="@blogNode.Url">@blogTitle</a><br />
        @(blogNode.GetPropertyValue<DateTime>("publishedDate").ToString("dd/MM/yyyy"))<br />
        <p>@blogNode.GetPropertyValue("excerpt")
                </p>
    
                <br />
        @blogNode.GetPropertyValue("author")
         </div>
                <div class="col-md-6">
            @if (blogNode.GetPropertyValue("featuredImage") != null)
                        {
                            var imageId = blogNode.GetPropertyValue("featuredImage");
                            var altText = blogNode.GetPropertyValue("alternativeImageText");
                            <a href="@blogNode.Url">    <img src="@Umbraco.Media(imageId).Url" alt="@altText" class="img-thumbnail centerImage" width="150px" /></a>
                        }
                        else
                        {
                            <a href="@blogNode.Url">     <img src="@Umbraco.Media(1925).Url" alt="New blog post" class="img-thumbnail" width="150px" /></a>
                        }
        </div>
    
         </div>            
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft