Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Dec 28, 2011 @ 09:42
    Anthony Candaele
    0

    no uBlogsy posts on homepage

    Hi,

    I want to have the latest 5 uBlogsy posts appear on my homepage. For that I implemented the uBlogsyListPosts.cshtml script on my Home template:

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

    But there are no uBlogsy posts appearing on my homepage:

    I don't know why there are no posts because I implemented this the same way on an other website (www.webmove.be) where it's working perfectly. The only difference with this other website is that on the not working website, the Blog node is not a child node of the home node:

    Could this be the problem?

    Does anyone has other suggestions why the posts aren't rendering on the homepage?

    Thanks for your help,

    Anthony

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 03, 2012 @ 10:51
    Anthony Dang
    0

    The cshtml file looks for the landing node going up the tree from the current node.

    In your case, your home node is a sibling of the landing node.

    I would either hardcode the id of the landing node, or do a search for it.

     

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

     

    This is my content tree: I am having the issue also of it just saying "Latest Posts", something I have to do other than link macro on homepage?

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

    Easiest fix is to hardcode the landing node id in the macro script.


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 18:43
    Anthony Candaele
    0

    Hi Pat,

    The reason why I didn't see the latest posts on my homepage was because it was not a child of the landingpage node. I fixed this by using this code in the uBlogsyListPosts.cshtml file:

    var landing new DynamicNode(Model.Id).Parent.GetChildrenAsList.Items.Where(=x.NodeTypeAlias == "uBlogsyLanding").Single();

    Hope this helps,

    Anthony

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

    Hi,

    When I do this, the homepage brings up an error through firebug : Error loading Razor Script uBlogsyListPosts.cshtml Object reference not set to an instance of an object.

    My current cshtml file looks like this:
    @{
        
        // get all posts
        IEnumerable<DynamicNode> postList = uBlogsy.Web.Helpers.NodeHelper.GetPosts(Model.Id);
        
        var landing = new DynamicNode(Model.Id).Parent.GetChildrenAsList.Items.Where(x => x.NodeTypeAlias == "uBlogsyLanding").Single();
        // get item count
        int count = int.Parse(@Parameter.ItemCount);

        IEnumerable<DynamicNode> nodes;

        if (@Parameter.Small == "1")
        {
            nodes = postList.Take(count);
            <div class="uBlogsy_posts_container uBlogsy_bottom_border">
            <h2>
                Latest posts</h2>
                <ul>
                    @foreach (DynamicNode n in nodes)
                    {
                        <li>
                            <a href="@n.Url">
                                <span>@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"];

            nodes = NodeHelper.GetPosts(tag, category, author, searchTerm, postList).Take(count).ToList();
            
            if (!string.IsNullOrEmpty(searchTerm))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h3>@nodes.Count() Results: </h3>
            }
             foreach (DynamicNode n in nodes)
             {
                   @RenderPage("/macroScripts/uBlogsyShowPost.cshtml", n.Id)
             }
        }
     }

    Apologies for layout, cant think how to make it look like code rather than plain text

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 18:58
    Anthony Candaele
    0

    Hi Pat,

    you should add this after 'var landing ...'

    IEnumerable<DynamicNodepostList uBlogsy.Web.Helpers.NodeHelper.GetPosts(landing.Id);

  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 19:01
    Pat
    0

    Have tried that as well, still same error coming up, strange.

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 19:47
    Anthony Candaele
    0

    Pat,

    To get this straight, the node that should read out the latest post is the 'Social Wallop' node?

  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 19:57
    Pat
    0

    Yes, that node is the home page, AboutUs is the 2nd page but the blog posts should appear on the SW Node, yes.

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 20:43
    Anthony Candaele
    0

    Maybe it's your version of uBlogsy. I'm using version 1.3.6.1

    Otherwise you can, like Anthony is saying, hard code your landing node:

      IEnumerable<DynamicNodepostList uBlogsy.Web.Helpers.NodeHelper.GetPosts(hardcoded landingnode id);


  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 21:01
    Pat
    0

    Thanks for your reply. I am using the same version.

    Sorry to be thick, but by hardcoded landing id do you mean the ID number which is under the properties tab of the destination page, e.g my social wallop bit?

    such as this : IEnumerable<DynamicNode> postList = uBlogsy.Web.Helpers.NodeHelper.GetPosts(1048);?

    Sorry don't mean to seem stupid, just been confused by it.

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 16, 2012 @ 21:11
    Anthony Candaele
    1

    Hi Pat,

    Indeed, it's the Id property (under 'properties' tab) of your landing node page (in your case the 'My Blog' page)

  • Pat 56 posts 147 karma points
    Jan 16, 2012 @ 21:37
    Pat
    0

    Thanks a lot Anthony. This now displays in a bulleted list. Glad they're on the homepage at last!

    Is it possible, rather than pulling through just the title as a link to the main article, to display the title and then underneath that say the first couple of lines of the post?

    Such as this:

    Even if it just pulled the title and say, the first 140 characters of the post?

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 17, 2012 @ 17:38
    Anthony Candaele
    0

    Hi Pat,

    You can just list a part of your body text using the Library.Truncate function.

    For example this is the way I show the first 300 characters of the body text:

    @(Library.Truncate(Library.StripHtml(body)300true))

    hope this helps,

    Anthony

  • Kiel Diller 24 posts 72 karma points
    Jan 22, 2012 @ 21:50
    Kiel Diller
    0

    I was able to make the script a bit more flexible by going to the macro and adding a parameter for "BlogNode" as a ContentPicker

    Then, when you add the macro to the screen you pick the landing page of the blog you wish to get posts for.

    Inside the script you can then do the following:

    // get all posts
        DynamicNode mynode = new DynamicNode(@Parameter.BlogNode);
        IEnumerable<DynamicNode> postList = uBlogsy.Web.Helpers.NodeHelper.GetPosts(mynode .Id);
       

    It took me forever to figure out I had to load the node as a DynamicNode rather than just feeding GetPosts a node ID. Maybe this will help some of you...

  • Oliver 5 posts 25 karma points
    Apr 23, 2012 @ 13:27
    Oliver
    0

    Hi,

    I've been trying to hardcode the landing node IDs to list latest posts for 3 blogs on various pages (on same site) using uBlogsy using....

    IEnumerable<DynamicNodepostList uBlogsy.Web.Helpers.NodeHelper.GetPosts(hardcoded landingnode id);

    but am getting the error "error CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'uBlogsy.Web' (are you missing an assembly reference?)"

    I am using uBlogsy 2.0.0.1.  Have the Helpers changed since the last post?

    Thanks

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

    Replace

    uBlogsy.Web.Helpers.NodeHelper

    with

    PostService.Instance

  • Nathan 2 posts 22 karma points
    Nov 23, 2012 @ 17:05
    Nathan
    0

    I'm having the exact same issue with my Umbraco setup. I have a List Categories macro that I'd like to appear on the home page.

    I figured it should be easy to hardcode the page Id into the GetPosts method of the macro but it is failing.

            DynamicNode blogBaseNode = new DynamicNode(1194);
            var nodes = PostService.Instance.GetPosts(blogBaseNode.Id);
            foreach (var n in nodes)
            {
                allCategories.AddRange(n.uBlogsyPostCategories.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            }

    Following the tip above, I instantiated a new DynamicNode and used it to GetPosts. However, this code fails when calling n.uBlogsyPostCategories.

    The original code was:

            var nodes = PostService.Instance.GetPosts(Model.Id);
            foreach (var n in nodes)
            {
                allCategories.AddRange(n.uBlogsyPostCategories.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            }

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Nov 23, 2012 @ 17:18
    Anthony Dang
    0

    try this:

       foreach (var n in nodes)

            {
                allCategories.AddRange(n.GetPropertyValue("uBlogsyPostCategories").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            }


  • Nathan 2 posts 22 karma points
    Nov 23, 2012 @ 17:26
    Nathan
    0

    That worked! Thanks for being so responsive. I've been banging my head on this for a day and a half after realizing the uBlogsy package that is installed through umbraco is not the latest version and will not work with my version of umbraco.

  • siriosus 3 posts 23 karma points
    Nov 25, 2012 @ 06:32
    siriosus
    0

    Hi,

    I faced with a similar problem - can't place blog posts on the homepage. I get this error - Error loading MacroEngine script (file: /uBlogsy/uBlogsyListPosts.cshtml). I tried to edit uBlogsyListPosts.cshtml according to your recommendations. I see this line - var landing = DataService.Instance.GetLanding(Model.Id); and tried to replece it like Anthony described but get the same error, and on the blog self homepage too. I use letest version of uBlogsy - 2.1.1.1. Is there a way to get blog posts on homepage in this version? 

    Thanks!

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Nov 28, 2012 @ 13:15
    Anthony Dang
    0

    siriosus can you paste your code and a snap of your content tree

  • Adam 51 posts 81 karma points
    Feb 04, 2013 @ 16:44
    Adam
    0

    I am having the same problem as siriousus. I've installed uBlogsy 2.1.1.0 and the site is structured...

    Home
      > About
      > Contact
      > Blog

    The uBlogsyListPosts.cshtml code is as follows:

    @using System.Linq
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @using uBlogsy.Common.Extensions
    @using uBlogsy.Common.Helpers
    @using uBlogsy.BusinessLogic
    @{
        const int ITEMS_PER_PAGE = 20; // for testing
    
        // get item count
        int count = int.Parse(@Parameter.ItemCount);
    
        IEnumerable<DynamicNode> nodes;
    
        if (@Parameter.Small == "1")
        {
            var posts = PostService.Instance.GetPosts(Model.Id);
            nodes = ((IEnumerable<DynamicNode>)posts).Take(count);
    
            <div class="uBlogsy_posts_container uBlogsy_bottom_border">
            <h2>@Dictionary["uBlogsyDicPostsLatest"]</h2>
                <ul>
                    @foreach (DynamicNode n in nodes)
                    {
                        <li>
                            <a href="@n.Url" title="@n.GetProperty("uBlogsyContentTitle").Value">
                                <span>@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"];
            var commenter = Request.QueryString["commenter"];
            int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1;
    
            IEnumerable<DynamicNode> posts = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count);
    
            // get landing node
            var landing = DataService.Instance.GetLanding(Model.Id);
    
    
    
            // only get posts where the path has the landing node's id.
            posts = posts.Where(x => x.Path.Contains(landing.Id + ","));
    
            nodes = posts.Take(count).ToList();
    
            int postCount = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, 0, int.MaxValue).Count;
    
            // pagination
            @RenderPagination(page, postCount, count)
    
            // render search result count when this script is displaying search results
            if (!string.IsNullOrEmpty(searchTerm))
            {
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('.uBlogsy_content_body').hide();
                    });
                </script>
                <h3>@nodes.Count() Results: </h3>
            }
    
            // show each post
            foreach (DynamicNode n in nodes)
            {
                @RenderPage("/macroScripts/uBlogsy/uBlogsyShowPost.cshtml", n.Id)
            }
        }
     }
    
    
    
    
    @helper RenderPagination(int page, int postCount, int itemsPerPage)
    {
        int pages = (int)Math.Ceiling((double)postCount / (double)itemsPerPage);
    
        string url = Request.Url.ToString();
        string querystring = Request.Url.Query;
    
        <ul id="uBlogsy_pagination">
    
            @* render prev link *@
            <li class="uBlogsy_page_prev">
                @if (page > 1)
                {
                    url = url.ReplaceQueryStringItem("page", (page - 1).ToString());
                    <a href="@url" >Prev</a>
                }else{
                    <span>Prev</span>
                }
            </li>
    
            @* render page links *@
            @for (int i = 1; i < pages+1; i++)
            {
                url = url.ReplaceQueryStringItem("page", i.ToString());
                string liClass = i == page ? "uBlogsy_current" : string.Empty;
    
                <li class="uBlogsy_page_item @liClass">
                    @if(page == i){
                        <span>@i</span> 
                    }else{
                        <a href="@url">@i</a>
                    }
                </li>
            }
    
            @* render next link *@
            <li class="uBlogsy_page_next">
                @if (page < Math.Ceiling((double)postCount/itemsPerPage))
                {
                    url = url.ReplaceQueryStringItem("page", (page + 1).ToString());
                    <a href="@url" >Next</a>
                }
                else
                {
                    <span>Next</span>
                }
            </li>
        </ul>
    }

    I've tried replacing...

    DataService.Instance.GetLanding(Model.Id);

    with...

    IEnumerable<DynamicNode> postList = PostService.Instance.GetPosts(1114);

    where 1114 is the ID for the blog's homepage. I'm sure I'm pasting the code in the wrong place so could someone please tell me exactly what and where i should edit?

     

    Many thanks!

  • Adam 51 posts 81 karma points
    Feb 04, 2013 @ 17:21
    Adam
    0

    Managed to post titles displaying on the homepage using the following suggestion from AnthonyDang (see this thread):

    Where you have this:

    var posts = PostService.Instance.GetPosts(Model.Id);

    Change to:

    var landingId = new DynamicNode(Model.Id).GetChildrenAsList.Items.Where(x => x.NodeTypAlias == "uBlogsyLanding").Single();
    var posts = PostService.Instance.GetPosts(landingId);

    How can I get the post descriptions to display? I know someone earlier in this thread was trying to do the same.

    Thanks

  • Adam 51 posts 81 karma points
    Feb 07, 2013 @ 12:10
    Adam
    0

    I think I need to update the following code in the uBlogsyShowPost.cshtml but have no idea how...

    @helper RenderPostBody(DynamicNode d)
        {
            string useSummary = DataService.Instance.GetValueFromLanding(Model.Id, "uBlogsyGeneralUseSummary");
            if (useSummary == "1"
                && Model.NodeTypeAlias == "uBlogsyLanding"
                && d.GetProperty("uBlogsyContentSummary").Value.Trim() != string.Empty
                )
            {
            @Html.Raw(d.GetProperty("uBlogsyContentSummary").Value)
            }
            else
            {
            @Html.Raw(umbraco.library.RenderMacroContent(d.GetProperty("uBlogsyContentBody").Value, d.Id))
            } 
    }

     Can anyone help?

    Many thanks!

  • Kiel Diller 24 posts 72 karma points
    Feb 07, 2013 @ 15:02
    Kiel Diller
    0

    I tried this and was able to get both the Small=1 scenario, and the full blog roll to work on my homepage. My setup is probably identical to yours. Keep in mind:

     

    • Hard code your landing ID EVERYWHERE you see "Model.Id"
    • If you created a new macro, make sure you actually added the parameters <-- I'm guessing this is one of your problems
    • any reference to "Model" will now be referencing your Home page (or wherever you are calling this) so you must remove things like
      if(useSummary =="1"
                 
      &&Model.NodeTypeAlias=="uBlogsyLanding"
                 
      && d.GetProperty("uBlogsyContentSummary").Value.Trim()!=string.Empty
                 
      )
      because Model.NoteTypeAlias will NOT be "uBlogsyLanding"
    • Make sure your posts actually have a summary, or the above block will fail again and you will end up in the bottom block of the "if"
Please Sign in or register to post replies

Write your reply to:

Draft