Display number of comments in a non default position? #116
-
Installed a third party module to display the latest published articles. Is there a way to have the number of article comments there? Like for example to add a code in the override of the module template? Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could do that in a template override with some custom code, assuming the “Content – Akeeba Engage” plugin is published. The plugin is required to load enough of the extension to make the following code possible $container = \FOF40\Container\Container\Container::getContainer('com_engage');
$commentsModel = $container->factory->model('Comments')->tmpInstance();
$numComments = $commentsModel->asset_id($article->asset_id)->count(); where If the $db = \JFactory::getDBO();
$query = $db->getQuery(true)->select($db->qn('asset_id'))->from($db->qn('#__content'))
->where($db->qn('id') . ' = ' . $db->q($article->id));
$assetId = $db->setQuery($query)->loadResult();
$container = \FOF40\Container\Container\Container::getContainer('com_engage');
$commentsModel = $container->factory->model('Comments')->tmpInstance();
$numComments = $commentsModel->asset_id($assetId)->count(); If you only have an article ID just replace Needless to say, Caveat: this code will no longer work in Akeeba Engage 3 which will no longer be using our FOF framework but will be rewritten as a native Joomla 4 MVC component. This is still quite a few months away, though 😉 |
Beta Was this translation helpful? Give feedback.
You could do that in a template override with some custom code, assuming the “Content – Akeeba Engage” plugin is published. The plugin is required to load enough of the extension to make the following code possible
where
$article
is the article record, assuming that the third party module also returns theasset_id
column for the article.If the
$article
object does not have theasset_id
column but only theid
(article ID) column you can add a database query to get the J…