Forum

Thread tagged as: Question, Comments

perch:noresults not working?

I have this on my page:

perch_comments('testimonials', array( template => 'comments_home.html', filter => 'commentHomepage', match => 'eq', value => 'yes', 'sort-order' => DESC ));

and in the comments_home.html I have a <perch:noresults> tag. However, if there are no results, it is not shown. Am I doing something wrong?

Lisa Morena

Lisa Morena 1 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

DESC needs to be quoted for a start.

What is shown when there's no comments? Can you post your template and diagnostics report?

Absolutely nothing! Template:

<perch:before>          
<div class="grey-bar"><div class="wrapper testimonials">
    <h2><span>Don't Take Our Word for it</span> What Our Clients Say</h2>
<div class="owl-carousel owl-theme">

</perch:before>

<div class="comment-container">
<div class="comment">
                <perch:comments id="commentHTML" html="true" encode="false" type="textarea" label="Feedback" order="4" required="true" />
                <div class="rating"><perch:if id="commentRating" match="eq" value="1*">&#9733;</perch:if><perch:if id="commentRating" match="eq" value="2*">&#9733;&#9733;</perch:if><perch:if id="commentRating" match="eq" value="3*">&#9733;&#9733;&#9733;</perch:if><perch:if id="commentRating" match="eq" value="4*">&#9733;&#9733;&#9733;&#9733;</perch:if><perch:if id="commentRating" match="eq" value="5*">&#9733;&#9733;&#9733;&#9733;&#9733;</perch:if> <perch:comments id="commentRating" type="text" label="Rating" order="1" required="true" suppress="true" /></div>
                        </div>
                <div class="commenter">

                    <span><perch:comments id="commentName" type="text" label="Name" order="2" required="true" /></span> <perch:if exists="commentClass"> - <perch:comments type="text" id="commentClass" label="Course Taken" order="3" supress="true" /></perch:if>
                </div>
    <perch:comments id="commentHomepage" type="checkbox" label="Show this on the homepage?" help="Try and keep the number of featured testimonials on the homepage to a maxium of 6 or 8" value="yes" suppress="true" title="true" /> 
        <perch:comments id="commentExcerpt" type="textarea" label="Homepage Excerpt" help="You should keep the featured testimonials on the homepage fairly short.  If this is a particularly long one, you can enter a shortened version here to show on the homepage (the full  testimonial will still show on the testimonials page)"  encode="false" html="true" suppress="true"/> 
    </div>

<perch:after>
            </div>
        </div>
      </div>  

</perch:after>
<perch:noresults>
No results stuff here
</perch:noresults>

Does perch_comments_count allow me to filter?

OK, so I found a way around this (don't know of it could be done in a tidier way but it works):

        <?php

    $comments =  perch_comments('testimonials', array(
        'skip-template' => true,
        'filter' => 'commentHomepage',
  'match' => 'eq',
    'value' => 'yes'), true);   

if (count($comments) >= 1) {

        perch_comments('testimonials', array(
    'template' => 'comments_home.html',
  'filter' => 'commentHomepage',
  'match' => 'eq',
    'value' => 'yes',
'sort-order' => 'DESC'
));     
    } else {  ?> <div> all my lovely no results stuff here </div>
<?php } ?>