Copied to clipboard

Flag this post as spam?

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


  • bob singh 47 posts 126 karma points
    Dec 03, 2013 @ 17:23
    bob singh
    0

    uBlogsy comment count

    Hi!

    I have installed uBlogsy and now I am trying to get the number of published comments under each post.

    This value will then be displayed on the landing page beside each post with the ccount variable.

    I am using this code but it is only bringing in the value of 0

      @{var ccount = node.Children.Where("NodeTypeAlias == uCommentsyComment").Count();

                              @Html.Raw(ccount + " comment");

    Would anyone know what I am doing wrong.

    Thanks!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 03, 2013 @ 19:44
    Jeavon Leopold
    0

    Hi Bob,

    Can you please show us how the variable "node" is set?

    Thanks,

    Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 03, 2013 @ 19:59
    Jeavon Leopold
    0

    I'm going to take a guess that it is the blog post itself, then you need to go one level deeper to get the comments as they are stored in a container node of type "uBlogsyContainerComment", something like this:

    @{
        var ccount = node.Children.Where("NodeTypeAlias == @0", "uBlogsyContainerComment").FirstOrDefault().Children.Where("NodeTypeAlias == @0", "uCommentsyComment").Count(); 
    }
    @Html.Raw(ccount + " comment")
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 03, 2013 @ 20:01
    Jeavon Leopold
    1

    You could also use Descendants, but this can have some performance issues if you have a lot of node.

    This would be like:

    @{
        var ccount = node.Descendants.Where("NodeTypeAlias == @0", "uCommentsyComment").Count(); 
    }
    @Html.Raw(ccount + " comment")
    
  • bob singh 47 posts 126 karma points
    Dec 04, 2013 @ 13:50
    bob singh
    0

    Hi Jeavon,

    I tried the following but it didnt work

       @{ var ccount = node.Children().Where("NodeTypeAlias == uCommentsyComment").Count();
                }
                    @Html.Raw(ccount + " comment")

     

    I know you mentioned the performance hit but as I dont see them creating too many post this works fine based on your second post -

       @{ var ccount = node.Descendants("uCommentsyComment").Count();
                }
                    @Html.Raw(ccount + " comment")

    Much appreciated!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 04, 2013 @ 16:01
    Jeavon Leopold
    0

    Hi Bob,

    Great, I think Descendants will be fine. Did you try my first suggestion as well, I'm pretty sure it works also?

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft