Jcomments pagination in tree view
Moderators: pe7er, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Apprentice
- Posts: 17
- Joined: Sun Sep 09, 2018 2:25 pm
Jcomments pagination in tree view
Jcomments is quite popular so I know many of you have tried it. In jcomments "flat view", pagination works great. The problem with the flat view is that, there are no "reply" buttons. In the "tree view" however, there are reply buttons but no pagination. The problem here is that, jcomments loads all the comments at once which severely affects the page load speed.
Please is there a way to get pagination to work in "tree view"? If no, is there a way to at least lazy load the comments? In other words, it would be great to have users click on "load more comments" to load additional comments instead of all comments at once.
Also, in case above doesn't work, is there a way to get the reply buttons to work in "flat view"?
Any help at all would be greatly appreciated. Thanks very much in advance.
Please is there a way to get pagination to work in "tree view"? If no, is there a way to at least lazy load the comments? In other words, it would be great to have users click on "load more comments" to load additional comments instead of all comments at once.
Also, in case above doesn't work, is there a way to get the reply buttons to work in "flat view"?
Any help at all would be greatly appreciated. Thanks very much in advance.
-
- Joomla! Apprentice
- Posts: 17
- Joined: Sun Sep 09, 2018 2:25 pm
Re: Jcomments pagination in tree view
I have been doing a lot of googling but still no luck. Any help at all would be greatly appreciated. Thanks very much.
-
- Joomla! Guru
- Posts: 734
- Joined: Wed Aug 15, 2018 8:23 pm
Re: Jcomments pagination in tree view
The nature of the "tree" view is not conducive to pagination since replies are appended to parent comments. If paging is applied, it could become confusing.
An accordion method is more suitable, similar to that of Facebook comments. The parent comments will display and below there would be a link to open the list of replies.
An accordion method is more suitable, similar to that of Facebook comments. The parent comments will display and below there would be a link to open the list of replies.
Re: Jcomments pagination in tree view
Even with the accordion the comments still go on endlessly though. If you happen to have a popular article there could potentially be hundreds of parent comments that the system loads on every view and the page will become super long. What about accordion with pagination tied to parent comments just to cut down the length, is that possible? Is something i was going to look into as well.
-
- Joomla! Guru
- Posts: 734
- Joined: Wed Aug 15, 2018 8:23 pm
Re: Jcomments pagination in tree view
The calculation required to determine when and at what point in replies to add pagination would be very complex and require AJAX requests to accurately load the associated replies. Then if there are quotes that are not in a reply but another parent comment, the confusion will be overwhelming. It's just not done in any system that has tree display.
Re: Jcomments pagination in tree view
Even with the collapsible comments? The only part that would need to be paginated would be the very top level (parent=0), and everything else ignored. When opened the replies wouldn't be paginated, just the initial list of (parent=0) commenst. I'm just asking, i know you know more about it than i do.
-
- Joomla! Guru
- Posts: 734
- Joined: Wed Aug 15, 2018 8:23 pm
Re: Jcomments pagination in tree view
The problem is that JComments tree creates endless sub- parents and replies with no specific ID to dynamically group in a pagination. One would need to set a method to disable sub-parenting after x count replies, and that alone is a complex process. Comment systems with tree view tend to use AJAX to load more when the user clicks the link.
Re: Jcomments pagination in tree view
Ok, thanks. It just seems odd that every forum has it that way but it can't be done with jcomments. I guess they've all done the calculations though. Would be nice if that part of the code could be borrowed.
-
- Joomla! Guru
- Posts: 734
- Joined: Wed Aug 15, 2018 8:23 pm
Re: Jcomments pagination in tree view
Forums operate differently with replies which would be equivalent to JComment's flat view. You'll notice that no tree effect is created in this Joomla PHPBB forum, the reply is added to the end of the thread and therefore will allow pagination since there is a proper count to define when to create a new page. In flat view, JComments will apply pagination.
-
- Joomla! Apprentice
- Posts: 17
- Joined: Sun Sep 09, 2018 2:25 pm
Re: Jcomments pagination in tree view
Please since pagination is "not" possible in the tree view, is there any other way to limit the number of comments in the tree view?
-
- Joomla! Apprentice
- Posts: 17
- Joined: Sun Sep 09, 2018 2:25 pm
Re: Jcomments pagination in tree view
@deleted user... Please sorry I couldn't reply to your PM. I'm not not allowed at this time. The good news however is that, I tried your method and it looks amazing. The only problem I have is the user profile link and the date (for both guests and registered users). Also, will jcomments avatar integrations (cmavatar, kunena, etc.) work with your method? Thanks very much for your great contribution.
Re: Jcomments pagination in tree view
Yeah sorry about that cosjla, that link was just a placeholder for a future module i was going to create so that users could view other users profiles, i just haven't made it yet. You can take the <a href></a> out from around the username php and that link will go away (in the tpl_comment file).
Not sure about other avatars, i've only used the gravatar option, that way i didn't have to host any avatars. Also which date? The member since date or the date the comment was posted? For guests the member since date will always be the current month and year, the registered should be ok though as long as your joomla is up to date and such. annahersh was nice enough to give me that code. You can always just remove that totally from tpl_comment if it's a problem though.
Glad it looked ok for you, i was wondering what it would look like for other users, and whether i included everything that was needed for it. I'm probably going to make it a bit more compact for my site eventually and change the toggles around a bit so they all appear on the same line. All of that is just a work around, i would much rather have it look a different way, like a list of topics with the pagination you were talking about and then you click them and the trees open up separately, kind of like the old imdb used to have. I just haven't been in the mood to work on anything lately, even put my site in standby for now. I'll probably take it off standby though, i just don't know if i'll be keeping up with some of the stuff for awhile, not going to be able to.
Also, make sure whatever changes you make to those 3 files you save someplace offline. If jcomments ever has another update it will overwrite them and you'll need to put them back.
Not sure about other avatars, i've only used the gravatar option, that way i didn't have to host any avatars. Also which date? The member since date or the date the comment was posted? For guests the member since date will always be the current month and year, the registered should be ok though as long as your joomla is up to date and such. annahersh was nice enough to give me that code. You can always just remove that totally from tpl_comment if it's a problem though.
Glad it looked ok for you, i was wondering what it would look like for other users, and whether i included everything that was needed for it. I'm probably going to make it a bit more compact for my site eventually and change the toggles around a bit so they all appear on the same line. All of that is just a work around, i would much rather have it look a different way, like a list of topics with the pagination you were talking about and then you click them and the trees open up separately, kind of like the old imdb used to have. I just haven't been in the mood to work on anything lately, even put my site in standby for now. I'll probably take it off standby though, i just don't know if i'll be keeping up with some of the stuff for awhile, not going to be able to.
Also, make sure whatever changes you make to those 3 files you save someplace offline. If jcomments ever has another update it will overwrite them and you'll need to put them back.
Re: Jcomments pagination in tree view
Alright so i finally got the pagination to work for tree view on jcomments. It only works on original comments, all reply trees will not be paginated, allows 10 first level comments per page right now.cosjla wrote: ↑Mon Sep 10, 2018 4:24 amJcomments is quite popular so I know many of you have tried it. In jcomments "flat view", pagination works great. The problem with the flat view is that, there are no "reply" buttons. In the "tree view" however, there are reply buttons but no pagination. The problem here is that, jcomments loads all the comments at once which severely affects the page load speed.
Please is there a way to get pagination to work in "tree view"? If no, is there a way to at least lazy load the comments? In other words, it would be great to have users click on "load more comments" to load additional comments instead of all comments at once.
Also, in case above doesn't work, is there a way to get the reply buttons to work in "flat view"?
Any help at all would be greatly appreciated. Thanks very much in advance.
You have to copy over public static function getCommentsTree in component/com_jcomments/jcomments.php and replace the whole function with:
Code: Select all
public static function getCommentsTree($object_id, $object_group = 'com_content', $page = 0)
{
$object_id = (int)$object_id;
$object_group = trim($object_group);
$user = JFactory::getUser();
$acl = JCommentsFactory::getACL();
$config = JCommentsFactory::getConfig();
$comments_per_page = $config->getInt('comments_per_page');
$limitstart = 0;
$total = JComments::getCommentsCount($object_id, $object_group, 'c.level = 0');
if ($acl->canComment() == 0 && $total == 0) {
return '';
}
if ($total > 0) {
$options = array();
$options['pagination'] = 'tree';
$options['object_id'] = $object_id;
$options['object_group'] = $object_group;
$options['published'] = $acl->canPublish() || $acl->canPublishForObject($object_id, $object_group) ? null : 1;
$options['votes'] = $config->getInt('enable_voting');
if ($comments_per_page > 0) {
$page = (int)$page;
require_once(JCOMMENTS_HELPERS . '/pagination.php');
$pagination = new JCommentsPagination($object_id, $object_group);
$pagination->setCurrentPage($page);
$pagination->setCommentsCount($total);
$total_pages = $pagination->getTotalPages();
$this_page = $pagination->getCurrentPage();
$limitstart = $pagination->getLimitStart();
$comments_per_page = $pagination->getCommentsPerPage();
$options['limit'] = $comments_per_page;
$options['limitStart'] = $limitstart;
}
$rows = JCommentsModel::getCommentsList($options);
} else {
$rows = array();
}
$tmpl = JCommentsFactory::getTemplate($object_id, $object_group);
$tmpl->load('tpl_tree');
$tmpl->load('tpl_comment');
if (count($rows)) {
$isLocked = ($config->getInt('comments_locked', 0) == 1);
$tmpl->addVar('tpl_tree', 'comments-refresh', intval(!$isLocked));
$tmpl->addVar('tpl_tree', 'comments-rss', intval($config->getInt('enable_rss') && !$isLocked));
$tmpl->addVar('tpl_tree', 'comments-can-subscribe', intval($user->id && $acl->check('enable_subscribe') && !$isLocked));
$tmpl->addVar('tpl_tree', 'comments-count', count($rows));
$tmpl->addVar('tpl_tree', 'comments-nav-bottom', 1);
if ($user->id && $acl->check('enable_subscribe')) {
require_once(JCOMMENTS_SITE . '/jcomments.subscription.php');
$manager = JCommentsSubscriptionManager::getInstance();
$isSubscribed = $manager->isSubscribed($object_id, $object_group, $user->id);
$tmpl->addVar('tpl_tree', 'comments-user-subscribed', $isSubscribed);
}
$i = 1;
JCommentsEventHelper::trigger('onJCommentsCommentsPrepare', array(&$rows));
if ($acl->check('enable_gravatar')) {
JCommentsEventHelper::trigger('onPrepareAvatars', array(&$rows));
}
require_once(JCOMMENTS_LIBRARIES . '/joomlatune/tree.php');
$tree = new JoomlaTuneTree($rows);
$items = $tree->get();
foreach ($rows as $row) {
// run autocensor, replace quotes, smilies and other pre-view processing
JComments::prepareComment($row);
// setup toolbar
if (!$acl->canModerate($row)) {
$tmpl->addVar('tpl_comment', 'comments-panel-visible', 0);
} else {
$tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
$tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($row));
$tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($row));
$tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($row));
$tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($row));
$tmpl->addVar('tpl_comment', 'button-ban', $acl->canBan($row));
}
$tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
$tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($row));
$tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($row));
$tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
$tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($row));
$tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($row));
$tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($row));
$tmpl->addVar('tpl_comment', 'button-report', $acl->canReport($row));
$tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar') && !$row->deleted);
if (isset($items[$row->id])) {
$tmpl->addVar('tpl_comment', 'comment-number', '');
$tmpl->addObject('tpl_comment', 'comment', $row);
$items[$row->id]->html = $tmpl->renderTemplate('tpl_comment');
$i++;
}
}
$tmpl->addObject('tpl_tree', 'comments-items', $items);
// build page navigation
if (($comments_per_page > 0) && ($total_pages > 1)) {
$tmpl->addVar('tpl_tree', 'comments-nav-first', 1);
$tmpl->addVar('tpl_tree', 'comments-nav-total', $total_pages);
$tmpl->addVar('tpl_tree', 'comments-nav-active', $this_page);
$pagination = $config->get('comments_pagination');
// show top pagination
if (($pagination == 'both') || ($pagination == 'top')) {
$tmpl->addVar('tpl_tree', 'comments-nav-top', 1);
}
// show bottom pagination
if (($pagination == 'both') || ($pagination == 'bottom')) {
$tmpl->addVar('tpl_tree', 'comments-nav-bottom', 1);
}
}
unset($rows);
}
return $tmpl->renderTemplate('tpl_tree');
}
Code: Select all
/*
*
* Display comments pagination
*
*/
function getNavigation()
{
if ($this->getVar('comments-nav-top') == 1
|| $this->getVar('comments-nav-bottom') == 1) {
$active_page = $this->getVar('comments-nav-active', 1);
$first_page = $this->getVar('comments-nav-first', 0);
$total_page = $this->getVar('comments-nav-total', 0);
if ($first_page != 0 && $total_page != 0) {
$object_id = $this->getVar('comment-object_id');
$object_group = $this->getVar('comment-object_group');
$content = '';
// number of visible pages
$pp = 10;
$fp = $active_page - $pp/2;
if ($fp <= 0) {
$fp = 1;
}
$lp = $fp + $pp;
if ($lp > $total_page) {
$lp = $total_page;
}
if ($lp - $fp < $pp && $pp < $total_page) {
$fp = $lp - $pp;
}
if ($fp > 1) {
$content .= '<span onclick="jcomments.showPage('.$object_id.', \''.$object_group.'\', '.($active_page-1).');" class="page" onmouseover="this.className=\'hoverpage\';" onmouseout="this.className=\'page\';" >«</span>';
}
for ($i=$fp; $i <= $lp; $i++) {
if ($i == $active_page) {
$content .= '<span class="activepage"><b>'.$i.'</b></span>';
} else {
$content .= '<span onclick="jcomments.showPage('.$object_id.', \''.$object_group.'\', '.$i.');" class="page" onmouseover="this.className=\'hoverpage\';" onmouseout="this.className=\'page\';" >'.$i.'</span>';
}
}
if ($lp < $total_page) {
$content .= '<span onclick="jcomments.showPage('.$object_id.', \''.$object_group.'\', '.($lp+1).');" class="page" onmouseover="this.className=\'hoverpage\';" onmouseout="this.className=\'page\';" >»</span>';
}
return $content;
}
}
return '';
}
Code: Select all
<h4>
<!-- start pagination code -->
<?php if ($this->getVar('comments-nav-top') == 1) { ?>
<div id="nav-top"><?php echo $this->getNavigation(); ?>
<?php } ?>
<!-- end pagination code -->
<?php echo $btnRSS; ?></div></h4>
There is a space between the pagination and the first comment. You can get it to set directly on top of the first comment by changing setting in components/com_jcomments/tpl/default/style.css.
Change #jc div#nav-top margin to margin: 10px 0 0 0;
Change #jc h4 padding to padding: 0 10px;
You can also set the pagination to the left instead of centered at #jc h4 if you want it on the left and not centered with text-align: left;
If you want to get rid of the space between the numbers find #jc #nav-bottom span and set margin to margin: 0;
Re: Jcomments pagination in tree view
As a consequence, if you use a latest comments module the comment title link might stop working. You have to disable it and just use the article link if this happens.
Re: Jcomments pagination in tree view
Correction, one change. The way the tag was displaying on the pages with only 1 page were screwing up the html. Had to replace the last code box from above, the one between th <h4> tag in tpl_tree.php to:
Also if you want to set the limit above 10, go to admin area of joomla and select components>jcomments>settings. In layout tab select flat view and then set the numbers there how you want them and click save. Then go back to layout tab and select tree and save. It will save the numbers you selected from the previous save.
Code: Select all
<h4>
<?php if ($this->getVar('comments-nav-top') == 1) { ?>
<div id="nav-top"><?php echo $this->getNavigation(); ?>
<?php echo $btnRSS; ?></div></h4>
<?php } else {
echo $btnRSS; ?>
<?php } ?>
</h4>
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Jan 31, 2011 1:09 am
Re: Jcomments pagination in tree view
For the last step, if you edit /administrator/components/com_jcomments/views/settings/tmpl/default.php you can add in the Comments Per Page, Comments Page Limit, and Comments Pagination settings to the Tree View (and not have to switch to List View to get it to save).
In the toggleListLayout function, around line 61
change:
to:
That should prevent the 3 new options for tree view from being hidden.
Hope that helps!
In the toggleListLayout function, around line 61
change:
Code: Select all
controls['list'] = ['jform[comments_list_order]', 'jform[comments_per_page]', 'jform[comments_page_limit]', 'jform[comments_pagination]'];
Code: Select all
controls['list'] = ['jform[comments_tree_order]'];
Hope that helps!
Re: Jcomments pagination in tree view
I'll have to check that out. Have you been able to incorporate a search function for bookmarks or anything past page 1? Currently if you have a link past page one it won't go there, just goes to the first page. Haven't been able to find any help with this.