×

Notice

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

TOPIC: Hack - "# of comments total" in title

Hack - "# of comments total" in title 15 years 5 months ago #4478

  • JonusC
  • JonusC's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 785
  • Thank you received: 48
Hello again.... :blush:

This one shows how many comments there are in total on the title bar. I think it's especially nice to have if you don't like the extended-info for the "Read More..." button. Here's a screenshot:



Here's the code changes. On line 1860 of comment.class.php...
$html 		= str_replace('{_JOOMLACOMMENT_COMMENTS_TITLE}', _JOOMLACOMMENT_COMMENTS_TITLE, $this->_menu);
...comment that out with // and below that insert this code block...
/* Hack by JonusC - get the total number of comments */
            $database =& JFactory::getDBO();			
            $com = $this->_component;
            $query = "SELECT COUNT(*) FROM jos_comment WHERE contentid='$this->_content_id' AND component='$com' AND published='1'";
            $database->SetQuery($query);
            $number = $database->loadResult();
            $html 		= str_replace('{_JOOMLACOMMENT_COMMENTS_TITLE}', _JOOMLACOMMENT_COMMENTS_TITLE." (".$number." total)", $this->_menu);
...thats it.

I don't know if that code is very good... i'm only new to this PHP language, but it shouldn't slow down the site much I hope...

Daniel, I also wanted to add a feature of showing "Oldest First" or "Newest First" in the Comment title, but for some reason the if ($this->_sort_downward) statement always returned false no matter what :blink: I have no idea why, could it be a bug or....... :unsure: here was the alternate code I was trying to use...
if ($this->_sort_downward) {
    $html 		= str_replace('{_JOOMLACOMMENT_COMMENTS_TITLE}', _JOOMLACOMMENT_COMMENTS_TITLE." (".$number." total, newest first)", $this->_menu);
} else {
    $html 		= str_replace('{_JOOMLACOMMENT_COMMENTS_TITLE}', _JOOMLACOMMENT_COMMENTS_TITLE." (".$number." total, oldest first)", $this->_menu);
}
...but it was always returning the 'oldest first' one, no matter what setting I had in Comments sorting. Is this because I have nested comments turned on?

Hack - "# of comments total" in title 15 years 5 months ago #4504

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey JonusC,
I've added the comment number to one of the trunk revisions.
compojoom.com/blog/8-news/81-some-improvements-.html
You can check it :) I think my implementation is a little bit better, because I'm not making any new database query.

About the sort_dowward - I will have to check this.

Hack - "# of comments total" in title 15 years 5 months ago #4518

  • JonusC
  • JonusC's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 785
  • Thank you received: 48
Ah, I havn't seen that! This is good, especially that you don't make a new database query to get it. I'll have to take a look at that code, thanks Daniel :)
  • Page:
  • 1
Time to create page: 0.212 seconds