Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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!
Hi Bob,
Can you please show us how the variable "node" is set?
Thanks,
Jeavon
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")
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")
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!
Great, I think Descendants will be fine. Did you try my first suggestion as well, I'm pretty sure it works also?
is working on a reply...
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.
Continue discussion
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!
Hi Bob,
Can you please show us how the variable "node" is set?
Thanks,
Jeavon
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:
You could also use Descendants, but this can have some performance issues if you have a lot of node.
This would be like:
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!
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
is working on a reply...
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.