Forum

Thread tagged as: Question

Comments pagination

How to get the comment pagination to work

Diagnossic Report

Summary information

Perch: 3.0.10, PHP: 5.4.45, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10), perch_blog (5.6.1), perch_forms (1.9.1), perch_members (1.6.1)
App runtimes: <?php $apps_list = ['perch_blog','perch_members','perch_forms' ];
PERCH_LOGINPATH: /bmcms
PERCH_PATH: /var/www/vhosts/mydomainpath/bmcms
PERCH_CORE: /var/www/vhosts/mydomainpath/subdomains/mydomainpath/core
PERCH_RESFILEPATH: /var/www/vhosts/mydomainpath/subdomains/mydomainpath/bmcms/resources
Image manipulation: GD Imagick
PHP limits: Max upload 16M, Max POST 128M, Memory: 128M, Total max file upload: 16M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /bmcms/core/settings/diagnostics/index.php
REQUEST_URI: /bmcms/core/settings/diagnostics/
DOCUMENT_ROOT: /var/www/vhosts/mydomainpath
HTTP_HOST: mydomain.co.uk

Post.php

            <?php   PerchSystem::set_var('page_tags.html',
            perch_blog_post_tags(perch_get('s'), [], true));
                    perch_blog_post(perch_get('s')); ?>
<?php 
perch_blog_post_comments(perch_get('s'), array(
'paginate' => true,
'count' => 2,
)); 
?>
    <?php perch_blog_post_comment_form(perch_get('s')); ?>


Comment.html

<perch:before>
<div class="row">
    <h2 class="fs-26">Comments and responses</h2>
    <div class="col-lg-12 pd-top-30">
</perch:before>
    <div class="col-lg-12 bor-top pd-top-20" id="comment<perch:blog id="commentID" type="hidden" />" >
<div class="col-lg-1">
    <img class="circle" src="//www.gravatar.com/avatar/<perch:blog id="commentEmail" type="email" label="Email" order="2" hash="md5" required="true" />?s=120&d=mm" width="75" height="75" />
</div>

<div class="col-lg-11">
    <div class="commenter">
    <perch:if exists="commentURL"><a href="<perch:blog id="commentURL" type="url" label="URL" order="3" />"></perch:if>
    <strong><perch:blog id="commentName" type="text" label="Name" order="1" required="true" />:</strong>
    <perch:if exists="commentURL"></a></perch:if>
    </div>
    <p rel="bookmark" class="comm-date"><perch:blog id="commentDateTime" format="%d %b %Y %X" type="date" time="true" label="Date" /></p>
    <perch:blog id="commentHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="4" />
</div>
</div>
<perch:after>
</div></div>
</perch:after>

Edward Johansen

Edward Johansen 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks fine - I think you just need to add the pagination tags to your template wherever you want them.

I have tried to add the pagination tags, but it did not work.

But, it was my mistake. I forgot to change <perch:content> to <perch:blog>

Thanks.

<perch:if exists="paging">
    <div class="paging">
        Comments <perch:blog id="current_page" type="hidden" />
            of <perch:blog id="number_of_pages" type="hidden" />
        <perch:if exists="not_first_page">
            <a href="<perch:blog id="prev_url" type="hidden" encode="false" />">Previous comments</a>
        </perch:if>
        <perch:blog id="page_links" encode="false" />
        <perch:if exists="not_last_page">
            <a href="<perch:blog id="next_url" type="hidden" encode="false" />">More comments</a>
        </perch:if>
    </div>
</perch:if>

Drew McLellan

Drew McLellan 2638 points
Perch Support

If in doubt, <perch:showall /> will show you what's available, and what tag namespace you should be using.

I just realized that is goes to the next page of comments, and losing the blog post content. Is there something to be changed in the pagination tag?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, most likely. So you have some sort of post slug or ID on the URL? If so you'll want to include that in your links.

Can you tell me what ID or url are you referring to? All info in my template is above. I been searching thread for hour for similar issue, with no luck. Thanks in advance

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you deciding which post to show on the page?

You need to make sure that whatever you're doing is carried through on the pagination URLs.

Hi Drew. This is a pagination to the blog comment,s. Imagine you have 50 comments in one single page. What I like to accomplish, is to have a blog comment pagination to click next and previous comments.

See the dev link below: stage.bergmedia dot co dot uk /blog/2017-10-21-blog-test

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so it looks like you have a blog slug. Is that slug on your pagination links?

Everything I have done so far is the one above. So can you guide me on how to achieve this?

I'm building my client network to change their CMS to Perch. I want to learn most of it before converting my clients to use your CMS.

Thanks in advance

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you click to go to page 2, is the post slug on the URL?

Post slug, you mean the blog title?

/blog/2017-10-21-blog-test

after clicking: /blog/post.php?s=2017-10-21-blog-test&page=2

But the blog post is not showing

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, that looks fine. I think you need to switch pagination off for the blog posts. It's trying to show page 2 of both listings, and there's no page 2 for your post.

This is part of my post.php

<?php   PerchSystem::set_var('page_tags.html',
perch_blog_post_tags(perch_get('s'), [], true));
perch_blog_post(perch_get('s')); ?>

How to disable pagination on perch_blog_post?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll either need to switch to perch_blog_custom() or set perch_blog_post_comments to use a different pagination-var option.

Thanks Drew.

or set perch_blog_post_comments to use a different pagination-var option

The above is my chosen option. How can I achieve that?

Using this does not render the pagination-var value:

                <?php   perch_blog_post_comments(perch_get('s'), array(
                    'paginate' => true,
                    'count' => 2,
                    'template' => 'comment.html',
                     'sort-order' => 'DESC',
                     'page-links' => true,
                     'pagination-var' => 'comm',
                        ));
                    ?>

Using the custom does not display comment content

                    <?php
perch_blog_custom(array(
    'template' => 'comment.html',
'paginate' => true,
'count' => 2,
'sort-order' => 'DESC',
'page-links' => true,
'pagination-var' => 'comm',
'page-link-template' => 'pagination/comments.html'
));
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

The point is that the two listings need different pagination var options. If you set them to the same you're back in the same position.

The thing is, pagination is only enabled in comments. Setting pagination-var in perch_blog_post_comments is not working, it still points to &page=

This is a simple task and I cannot get it to work, and it's disappointing. Maybe you can have a look at my post.php below and see what i'm doing wrong. Thanks

Post.php

<?php include('../bmcms/runtime.php'); ?>
<?php perch_layout('blog_header'); ?>
    <div class="container-fluid pd-top-150 xs-pd-top-100">

<div class="container">
    <div class="row">
        <div class="col-lg-8 col-md-8 pd-right-100 xs-pd-right-15 sm-pd-right-15 md-pd-right-50 masonry-container">

            <!--* Display blog posts *-->

            <?php PerchSystem::set_var('page_tags.html',
            perch_blog_post_tags(perch_get('s'), [], true));
            perch_blog_post(perch_get('s')); ?>

            <?php   perch_blog_post_comments(perch_get('s'), array(
                    'template' => 'comment.html',
                    'paginate' => true,
                    'count' => 2,
                    'sort-order' => 'DESC',
                    'pagination-var' => 'comm',
                    ));
                ?>
<?php perch_blog_post_comment_form(perch_get('s')); ?>
</div>
    <!--* side column *-->
<div class="col-lg-4 col-md-4 lp-sidebar">
<aside>
            <h2>Latest posts</h2>
            <?php
            perch_blog_custom(array(
                'count'      => 5,
                'paginate' => false,
                'template'   => 'custom/post_recent_list.html',
                'sort'       => 'postDateTime',
                'sort-order' => 'DESC',
                'filter' => 'postSlug',
                'hide-extensions' => true,
                'match' => 'neq',
                'value' => perch_get('s'),
                ));
            ?>
</aside>
</div>
</div>
</div>
</div>
<?php perch_layout('footer_standard_no_preview_scipt'); ?>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Have you tried what Drew is suggesting, to set a different var for each? It's difficult to help if we don't know whether you are acting on the advice given.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

I tested this and I can confirm that perch_blog_post_comments() seems to ignore the pagination-var option and always uses the default ?page.

Since the pagination-var option works in perch_blog_custom(), change it to something other than the default page to achieve what Drew suggested; setting different pagination-vars for each one (your post and your comments).

// set pagination-var when displaying your post
perch_blog_custom([
    'filter' => 'postSlug',
    'match' => 'eq',
    'value' => perch_get('s'),
    'pagination-var' => 'anything',
]);

// pagination-var here is always the default 'page'
perch_blog_post_comments(perch_get('s'), [
    'template' => 'comment.html',
    'paginate' => true,
    'count' => 2,
    'sort-order' => 'DESC',
]);