Comment Count In Pagelist
Permalink 1 user found helpful
I am trying to get the comment count in pagelist.
This is the default template. Apparently the method does not exist because it is not returning anything.
Any Ideas?
This is the default template. Apparently the method does not exist because it is not returning anything.
if(method_exists($entryController,'getCommentCountString')) { $comments = $entryController->getCommentCountString('%s '.t('Comment'), '%s '.t('Comments')); }
Any Ideas?
Has anybody got a comment counter in a pagelist working in 5.6?
There are many postst about this subject, but I can't get one to work.
Best regards,
Nick
There are many postst about this subject, but I can't get one to work.
Best regards,
Nick
I just tested this out on Concrete5.6.1 and it worked fine. What exactly is the problem you're having? Can you post the code that you're trying to use?
I used the code exact as you described, in a default page list. I get the 'comments disabled' message, but I've added and approved three comments. Thnx!
EDIT: if I comment out the if statement in the helper, the counter works:
Pagelist:
EDIT: if I comment out the if statement in the helper, the counter works:
public function comment_count_string($collectionObject, $singular_format, $plural_format, $disabled_message = '') { //if ($this->comments_enabled($collectionObject)) { $count = $this->comment_count($collectionObject); $format = ($count == 1 ? $singular_format : $plural_format); return sprintf($format, $count); //} else { // return $disabled_message; //} }
Pagelist:
<?php defined('C5_EXECUTE') or die("Access Denied."); $rssUrl = $showRss ? $controller->getRssUrl($b) : ''; $th = Loader::helper('text'); $cc_phrase_singular = '%d comment'; $cc_phrase_plural = '%d comments'; $cc_phrase_disabled = 'Comments disabled'; $cch = Loader::helper('comment_count'); ?> <div class="ccm-page-list"> <?php foreach ($pages as $page): $title = $th->entities($page->getCollectionName()); $url = $nh->getLinkToCollection($page); $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target'); $target = empty($target) ? '_self' : $target;
Viewing 15 lines of 28 lines. View entire code block.
Sorry, but I don't know why it wouldn't be working properly on your site. Your solution to the problem looks like a good one though.
Thank you very much for posting this excellent little helper and calling code, which just saved me a stack of time trying to work out how to fetch the number of approved posts :)
[ Works with 5.6.2.2b2 ]
[ Works with 5.6.2.2b2 ]
This is a really helpful thread; having used the comment_count.php and also the changes to the pagelist custom template I thought I'd post a couple of additions to them, to show not only the comment count, but the last comment author and date.
Firstly, here's the comment_count.php file which should go in your helpers folder (not /concrete/helpers);
Now create a new pagelist template - I put a new folder called "mytemplate" here; .\blocks\page_list\templates and added a view.php in this folder. Here's the code for the view.php;
Hope that saves someone a little time.
Firstly, here's the comment_count.php file which should go in your helpers folder (not /concrete/helpers);
<?php defined('C5_EXECUTE') or die("Access Denied."); class CommentCountHelper { public function comment_count_string($collectionObject, $singular_format, $plural_format, $disabled_message = '') { //if ($this->comments_enabled($collectionObject)) { $count = $this->comment_count($collectionObject); $format = ($count == 1 ? $singular_format : $plural_format); return sprintf($format, $count); //} else { // return $disabled_message; //} } public function comment_get_last($collectionObject) { //if ($this->comments_enabled($collectionObject)) { $count = $this->comment_count($collectionObject); if ($count > 0)
Viewing 15 lines of 57 lines. View entire code block.
Now create a new pagelist template - I put a new folder called "mytemplate" here; .\blocks\page_list\templates and added a view.php in this folder. Here's the code for the view.php;
<?php defined('C5_EXECUTE') or die("Access Denied."); $rssUrl = $showRss ? $controller->getRssUrl($b) : ''; $th = Loader::helper('text'); $cc_phrase_singular = '%d comment'; $cc_phrase_plural = '%d comments'; $cc_phrase_disabled = 'Comments disabled'; $cch = Loader::helper('comment_count'); ?> <div class="ccm-page-list"> <?php foreach ($pages as $page): $title = $th->entities($page->getCollectionName()); $url = $nh->getLinkToCollection($page); $date = $page->getCollectionDatePublic(DATE_APP_GENERIC_MDY_FULL); $author = $page->getVersionObject()->getVersionAuthorUserName();
Viewing 15 lines of 55 lines. View entire code block.
Hope that saves someone a little time.
Then in your page list template, put this code *before* the foreach loop starts:
(you'll want to customize the first 3 lines depending on what messages you want to display -- the %d thing is a placeholder where the comment count number will go so you need that in the first two).
Then put this code *inside* the foreach loop, where you want the message outputted:
Note that this code is from a ways back, so I'm not 100% sure it still works... but it probably does.
-Jordan