Copied to clipboard

Flag this post as spam?

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


  • tesuji 95 posts 139 karma points
    Aug 11, 2011 @ 21:38
    tesuji
    0

    Show latest blog post on home page?

    I'm new to uBlogsy - is there an easy way to display just the latest blog post, on my home page?

    I'm also assuming I can use uBlogsy on an existing Umbraco site, to show up as a regular page on my site. I saw another thread here "Easy way to integrate to an existing site" which seems to indicate that, but I haven't dug into it yet to figure out exactly how that works.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 11, 2011 @ 21:43
    Anthony Dang
    0

    Hi 

    Yes you can integrate it into a site very easily. Just take a look at the base master pages. The only requirement is the landing node (and the posts node if you want to use the rss import). 

    As far as listing the latest blogs, the rip some code out of uBlogsyListPosts.cshtml, or you can call the macro with ItemCount=1

            <umbraco:Macro ID="Macro2" Alias="uBlogsyListPosts" ItemCount="1" Small="0" runat="server" />

     

     

     

  • FarmFreshCode 225 posts 422 karma points
    Aug 19, 2011 @ 15:25
    FarmFreshCode
    0

    Hey Guys,

    I'm trying to pull the most recent stories onto my hompage as well. I had it set up with Blog4Umbraco like this:

    And would love to get the same result from UBlogsy.. I've tried using <umbraco:Macro ID="Macro2" Alias="uBlogsyListPosts" ItemCount="1" Small="0" runat="server" /> as mentioned by Anthony but it doesn't seem to generate any results for me..

    @Anthony, is that something that works in v1.32?  I see that v.1.33 is out.. but I haven't updated to it yet.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 22, 2011 @ 17:33
    Anthony Dang
    1

    I noticed Small=0 in yoru macro call. Make it small=1

    <umbraco:Macro Alias="uBlogsyListPosts" ItemCount="5" Small="1" runat="server" />

     

    If you want custom html for it you'll have to copy the script and create a new macro. 

  • FarmFreshCode 225 posts 422 karma points
    Aug 22, 2011 @ 17:57
    FarmFreshCode
    0

    Hi Anthony,

    Yeah that helped some.. I can now see the title "Latest Posts" but no stories show up with it..
    I know I made some modifications when I was creating my own paging solution so if you wouldn't mid look at the code below to see if I have created a conflict I would apprecaite it:

    @using System.Linq
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @using uBlogsy.Web.Extensions
    @using uBlogsy.Web.Helpers
    @using System.Xml
    @using AP.Umbraco.Repository.Code

    @{
        
        // get all posts
        IEnumerable<DynamicNode> postList = new DynamicNode(Model.Id)
                                        .AncestorOrSelf(1)
                                        .DescendantsOrSelf("uBlogsyPost")
                                        .Items
                                        .Where(x => x.GetProperty("umbracoNaviHide").Value != "1");

        // get item count
        int count = int.Parse(@Parameter.ItemCount);
        
        var paging = Paging.GetPages(postList.Count(), 10);
        var selectedNodes = postList.OrderByDescending(x => x.GetProperty("uBlogsyPostDate").Value)
                            .Skip(paging.Skip)
                            .Take(paging.Take)
                            .ToList();


        List<DynamicNode> nodes;

        if (@Parameter.Small == "1")
        {
            nodes = postList.OrderByDescending(x => x.GetProperty("uBlogsyPostDate").Value)
                            .Take(count)
                            .ToList();
            <div class="uBlogsy_posts_container uBlogsy_bottom_border">
            <h2>Latest posts</h2>
                <ul>
                    @foreach (DynamicNode n in nodes)
                    {
                        <li style="border-bottom:1px solid #ccc4ad; padding-bottom:5px; margin-bottom:5px; padding-left:20px;">
                            <a href="@n.Url" title="@n.GetProperty("uBlogsyContentTitle")">
                                <span class="uBlogsy-latestposts">@n.GetProperty("uBlogsyContentTitle").Value</span>
                            </a>
                           @* - <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy")</span>*@
                        </li>
                    }
                </ul>
            </div>
        
         
        }
        else
        {
            
            
            // get tag, category, or author from query string
            var tag = Request.QueryString["tag"];
            var category = Request.QueryString["category"];
            var author = Request.QueryString["author"];
            var searchTerm = Request.QueryString["search"];

      
            postList = NodeHelper.GetPosts(tag, category, author, searchTerm, postList).Take(count).ToList();

            // get item count
            count = int.Parse(@Parameter.ItemCount);

            paging = Paging.GetPages(postList.Count(), 10);
            
            selectedNodes = postList.OrderByDescending(x => x.GetProperty("uBlogsyPostDate").Value)
                                .Skip(paging.Skip)
                                .Take(paging.Take)
                                .ToList();

            if (!string.IsNullOrEmpty(searchTerm))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h1>@selectedNodes.Count Results for: @searchTerm</h1>
            }

            if (!string.IsNullOrEmpty(category))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h1>Category: @category</h1>
            }

            if (!string.IsNullOrEmpty(author))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h1>@selectedNodes.Count Results for: @author</h1>
            }
            if (!string.IsNullOrEmpty(tag))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h1>@selectedNodes.Count Results for: @tag</h1>
            }


            foreach (DynamicNode n in selectedNodes)
            {
                   @RenderPage("/macroScripts/uBlogsyShowPost.cshtml", n.Id)
             }
         
             
        }
      
    if (@Parameter.hasPaging == "1")  
    {
      <div id="pager">
        <ul>@Paginator.RenderPaging(paging, Current.Id)</ul>
      </div>
    }     
     }

    Thats what my uBlogsyListPosts.cshtml file looks like at the moment..

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 22, 2011 @ 18:01
    Anthony Dang
    0

    Hard to tell

    You should debug it by deleting things until it works.

    Start with everything in your "else" 

  • tesuji 95 posts 139 karma points
    Sep 01, 2011 @ 17:49
    tesuji
    0

    Anthony, you said: "Yes you can integrate it into a site very easily. Just take a look at the base master pages. The only requirement is the landing node (and the posts node if you want to use the rss import). "

    Can you give me a little more detail about what to do? I've looked at the master pages, but I'm kind of new to Umbraco.

  • tesuji 95 posts 139 karma points
    Sep 01, 2011 @ 17:52
    tesuji
    0

    I don't need the RSS import, by the way

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Sep 01, 2011 @ 18:22
    Anthony Dang
    0

    uBlogsyBaseSite has the <html> dec. You should make that masterpage inherit from YOUR masterpage which has <html>

    I think your best bet is to look into masterpage tutorials: http://www.asp.net/master-pages/tutorials

  • tesuji 95 posts 139 karma points
    Sep 08, 2011 @ 16:09
    tesuji
    0

     

    I put the following in my home page master template to show the latest post only, but it doesn't show the post.

    <umbraco:Macro Alias="uBlogsyListPosts" ItemCount="1" Small="1" runat="server" />

     

     

    Looking at the output in browser View Source, it only shows the following:

     

    <div class="uBlogsy_posts_container uBlogsy_bottom_border">

    <h2>

    Latest posts</h2>

    <ul>

    </ul>

    </div>

     

    My main blog page works fine - it lists several posts.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Sep 12, 2011 @ 18:03
    Anthony Dang
    0

    This will happen if you do not have the ublogsy landing node under the node(page) you're trying to use the macro on.

    eg.

    Content
    - Home
    - Blog

    The script relies on the fact that it is being used on either the uBlogsy Landing page, or a descendent of the landing page.

    If this is the case then you need to modify the macro script to get the ublogsy landing node.

    If this is not the case, can you copy and paste your content tree here.

     

     

     

     

  • FarmFreshCode 225 posts 422 karma points
    Sep 16, 2011 @ 20:49
    FarmFreshCode
    0

    Hi Anthony,

    I'm still at the same point as [tesuji] any chance you could provide a sample macro that we could use since we both seem to have the blog as sub-section to our sites.

    I assume I just need to make a new macro and modify the call that looks for current/decendent to the specific nodeID of my uBlogsy blog.. but I haven't been able to get it to work so far..
    Thanks!

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Sep 16, 2011 @ 23:11
    Anthony Dang
    2

    guys this is how you do it:

     

     

        // get all posts
        IEnumerable<DynamicNodepostList new DynamicNode(<ID OF UBLOGSY LANDING NODE>)
                                        .DescendantsOrSelf("uBlogsyPost")
                                        .Items
                                        .Where(=x.GetProperty("umbracoNaviHide").Value != "1");

       
        List<DynamicNodenodes postList.OrderByDescending(=x.GetProperty("uBlogsyPostDate").Value)
                        .Take(10)
                        .ToList();
        <div class="uBlogsy_posts_container uBlogsy_bottom_border">
        <h2>
            Latest posts</h2>
            <ul>
                @foreach (DynamicNode in nodes)
                {
                    <li>
                        <href="@n.Url">
                            <span>@n.GetProperty("uBlogsyContentTitle").Value</span>
                        </a>
                       @<span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy")</span>*@
                    </li>
                }
            </ul>
        </div>
     
  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 13:01
    Pat
    0

    Sorry to bump old thread, but I am trying to do this today!

    When I call the Macro, it literally just displays the H2 tagged Latest Posts line, and that is it. Then under that is the ID of the blog im trying to show as I have called it out too.

     

    Any help please?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 16, 2012 @ 13:14
    Anthony Dang
    0

    Is the ublogsy landing node not under the home page node?

    If so, then you will have to either hardcode it's id in the macro script, or do a search for it.

     

     

  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 13:18
    Pat
    0

    I have put the uBlogsy blog under the home node in my content tree, if that is what you mean?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 16, 2012 @ 18:22
    Anthony Dang
    0

    Sorry my mistake

    The macro script won't work unless you're running it from the landing node, no matter where that is.

    Easiest fix is to hardcode it's id in the macro script.


  • tesuji 95 posts 139 karma points
    May 01, 2012 @ 11:19
    tesuji
    0

    Does all this still hold for uBlogsy 2.1? If not, please tell me how to do it.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    May 01, 2012 @ 12:20
    Anthony Dang
    0

    yes

  • tesuji 95 posts 139 karma points
    May 02, 2012 @ 00:04
    tesuji
    0

    I got the following to work. It shows the first three blog items on the home page.

    I put this into a new .cshtml file in the Developer -> Scripting Files folder in Umbraco, and they wrapped it in a macro.

     

    @using System.Linq

    @using System.Xml.Linq

    @using umbraco.MacroEngines

    @using uBlogsy.Common.Extensions

    @using uBlogsy.Common.Helpers

    @using uBlogsy.BusinessLogic

    @{

      // get all posts

        IEnumerable<DynamicNode> postList = new DynamicNode(1083)

                                        .DescendantsOrSelf("uBlogsyPost")

                                        .Items

                                        .Where(x => x.GetProperty("umbracoNaviHide").Value != "1");

     

       

        List<DynamicNode> nodes = postList.OrderByDescending(x => x.GetProperty("uBlogsyPostDate").Value)

                        .Take(3)

                        .ToList();

                        

        <div class="uBlogsy_posts_container uBlogsy_bottom_border">

        <h2>

            Latest posts</h2>

            <ul>

                @foreach (DynamicNode n in nodes)

                {

                    <li style="list-style: none;">

                   <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy")</span>

                   <br>

                        <a href="@n.Url">

                            <span>@n.GetProperty("uBlogsyContentTitle").Value</span>

                        </a>

                        <br>

                        @Truncate(umbraco.library.RenderMacroContent(n.GetProperty("uBlogsyContentBody").Value, n.Id), 500) 

    <a href="@n.Url">Read More</a>

                      

                    </li>

                }

            </ul>

        </div>

        

    }

     

    @helper Truncate(string input,int length)

    {

         if(input.Length <= length){

             @Html.Raw(input)

         } else {

             @Html.Raw(input.Substring(0,length))<text>...</text>

         }

    }

        

        

  • Amir Khan 1282 posts 2739 karma points
    Mar 27, 2013 @ 21:15
    Amir Khan
    0

    Is there a way to do this while still keeping the "blog" oustide of the root of the site? How would you go about rendering the blog content in another template that matched the site?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 28, 2013 @ 19:10
    Anthony Dang
    0

    Amir can you explain more what you're trying to do? I'm not sure I understand.

    A picture of your content tree would help too.

     

  • Amir Khan 1282 posts 2739 karma points
    Mar 28, 2013 @ 19:15
    Amir Khan
    0

    Hi Anthony, here's the setup.

    I have one uBlogsy Blog which has several categories, each corresponding to a "site". So there's category 1 which the user will tag if they want the blog post to appear on site one, etc. I have no problem getting the list of latest posts, posts by tags, etc into any of my sites via a razor macro. My challenge is that each of the sites have a different master template and I'm not sure how to keep the link to the full blog post within the site that the abstract is posted on via a razor macro...and have it render inside a template appropriate to that site.

    Here the content tree:

Please Sign in or register to post replies

Write your reply to:

Draft