×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: use compojoom in search results and FJ Related

use compojoom in search results and FJ Related 12 years 9 months ago #15117

  • Geoffrey Ellison
  • Geoffrey Ellison's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 0
Hi,

Apologies if I'm posting this to the wrong place, please feel free to move it to another category.

I've managed to use commenting in a custom layout (built with template overrides) for the category blog and the featured blog layouts. I'm using "afterDisplayContent" to show number of comments with the "Read More link". It works very well, good work on this extension.

Now I hope to get the same functionality (show comments next to "Read More" link) for search results (Joomla built-in com_search) and FJ Related (com_fjrelated). I've built custom layouts for both of these also, using template overrides, to make the layout the same as the above blog layouts.

Can you advise the best way to get number of comments to show in search results (and in FJ Related blog) next to the "Read More"? Do I need to create a plugin for each component, or maybe plugins already exist for these?

I'm an experienced programmer, so please feel free to go into detail.

Thanks in advance

Geoff.

Re: use compojoom in search results and FJ Related 12 years 9 months ago #15120

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Geoffrey,
that is a cool idea actually! Once you are ready please share your final override with us - maybe other users will find that useful as well.

I think that the easiest way to do this thing would be to create a countComment function that should accept a (articleId, option/component)

I haven't looked in details of the search component, but I imagine that when it builds the list of the found result - you have the id of the article and you know if it is a com_content or com_contact item - you'll pass those 2 to your countComment function.

the countComment function will be a simple db query - something like this:
select count(*) from #__comment where component = com_content/com_contact articleId="the articleid"

Do you get the idea?

Daniel
The following user(s) said Thank You: Geoffrey Ellison

Re: use compojoom in search results and FJ Related 12 years 9 months ago #15193

  • Geoffrey Ellison
  • Geoffrey Ellison's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 0
Hey Daniel,

Thanks for that suggestion, I've made a function that returns the number of comments. No doubt many people will say it can be shortened, but I am going for easy readability by those who come after me. Of course, it can be used in any override, not only FJ Related. I'm also using it in a com_search override. Here it is:
function cu_GetCommentCount($id, $component = 'com_content') {
	//this function gets a count of comments for the given content item
 
	$result = false;
	$db = JFactory::getDBO();
	$query = $db->getQuery(true);
	$query->select('COUNT(id)');
	$query->from('#__comment');
	$query->where('component = '.$db->quote($component));
	$query->where('contentid = '.$db->quote(intval($id)));
	$db->setQuery($query);
	$count = $db->loadResult();
	if ($count !== false) { $result = intval($count); }
	return $result;
}

Hope this helps someone!

Geoff.

Re: use compojoom in search results and FJ Related 12 years 9 months ago #15196

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
That is awesome Geoff! Thank you for sharing this code with us!
Daniel
  • Page:
  • 1
Time to create page: 0.154 seconds