Sep 6, 2017

Display comment information for a blog on Orchard CMS sites with multiple blogs

Update (13/09/2017) Someone made a pull request where there is a much simpler way to do this than my mad HQL queries as Comments contain a field with the id of the container (e.g. the blog). Grab the pull request here

I manage a website with multiple blogs and this issue brought to my attention that on the admin summary for a blog (not a blog post) it displays comment information that doesn't actually work. To be honest, I had never even noticed that it displays any comment information at all. After initially flicking this off as a useless feature and we should remove the broken code from the comments module (I still am leaning toward this not being needed for core), I actually figured that this could actually be a pretty cool feature so I threw together a little module for it. You can grab the source on GitHub.

The use enable the feature 'Blog Comment Count' and attach the ContainerCommentsCountPart to your Blog type.

The module stores the comment counts as aggregates in a new part so there should hopefully be no performance loss when rendering the admin summary shapes for a blog. The counts are calculated in the background when a comment is created or moderated for a blog. I had to dust off my HQL skills because I needed the SUM keyword, which Orchard's query API does not expose (that I could see anyway). It also hides the broken comment count display that comes from Orchard.Comments.

Tags: orchard


  • Rob said Reply

    Hi, I'm the guilty party who logged the issue :)

    The use case I thought of for this is for a site admin to keep an eye on blogs (with separate owners) and the number of comments against them, though the "best" solution here would be if the comment count was broken out to also show "pending count". Other than that, the fact that Orchard showed "0" just rankled... ;)

    • admin said Reply

      It does indeed show a pending and total count. I think the pull request someone made also does this and in a much simpler way since comments contain a container field. As per usual, I overcomplicated something very simple ha

Add a Comment