Getting my Heading inside of exp:rating:entries tag to only show when there are ratings
Posted: 09 April 2008 08:13 PM   [ Ignore ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

I’ve got this code to display the ratings/reviews that have been left by visitors:

{exp:rating:entries}
  {if count
== 1}
  
<hr />
  <
h2>What Other Golfers Think of This Course</h2>
  
{/if}
  
<div id="reviews" class="clearfix">
   <
div class="reviewerInfo">
    <
p class="strong">{rating_name}</p>
    <
p class="reviewsStarsAuthor">{stars}{rating}{/stars}</p>
    <
p class="reviewsDate">{rating_date  format="%F %j, %Y"}</p>
   </
div>
   <
div class="review">
    <
p class="reviewTitle">{review_title}</p>
    <
p class="reviewBody">{review}</p>
    <
p class="reviewHelpfulStats">
    
{exp:rating:rating_rev_stats rating_id="{rating_id}"}
    {y} golfers thought this review was helpful
.
    
{/exp:rating:rating_rev_stats}
    
</p>
    <
p class="reviewHelpful">Was this review helpful to you? <a href="#" title="Yes">Yes</a> | <a href="#" title="No">No</a></p>
   </
div>
  </
div>
  
{/exp:rating:entries}

What I’m attempting to do is only show the <h2> tag when there is one or more entries. I’ve done similar things using the {if count == 1} conditional before but only with weblog:entries. I’m not sure it works with rating:entries?

I tried {if count >=1} as well with no luck. Using these the conditionals, completely removes the heading even when there are reviews (when it should show).

Profile
 
 
Posted: 10 April 2008 10:36 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3343
Joined  2006-10-18

Using {if count == 1} will only show if the count is EQUAL TO 1
You would need to use {if count >= 1} as that will show if the count is GREATER THAN OR EQUAL TO 1

Secondly, you would probably be looking for a variable like {total_count}
Lastly, because it’s within the loop, that heading will appear for EVERY entry.

All that said… none of those variables are available, hence the conditional is not available rasberry LOL

However, a simple workaround:

{exp:rating:entries limit="1"}
  
<hr />
  <
h2>What Other Golfers Think of This Course</h2>
  
{/exp:rating:entries}

{exp:rating:entries}
  
<div id="reviews" class="clearfix">
   <
div class="reviewerInfo">
<
p class="strong">{rating_name}</p>
<
p class="reviewsStarsAuthor">{stars}{rating}{/stars}</p>
<
p class="reviewsDate">{rating_date  format="%F %j, %Y"}</p>
   </
div>
   <
div class="review">
<
p class="reviewTitle">{review_title}</p>
<
p class="reviewBody">{review}</p>
<
p class="reviewHelpfulStats">
{exp:rating:rating_rev_stats rating_id="{rating_id}"}
{y} golfers thought this review was helpful
.
{/exp:rating:rating_rev_stats}
</p>
<
p class="reviewHelpful">Was this review helpful to you? <a href="#" title="Yes">Yes</a> | <a href="#" title="No">No</a></p>
   </
div>
  </
div>
  
{/exp:rating:entries}

If there are no entries, neither will show. If there is 1 or more entries, all will show as you wish. The limit parameter on the loop with the heading will stop the heading from showing X times the amount of ratings.

Another option available is to use the {if no_results}No results to display.{/if} conditional, but you’d still need to use two loops like above rasberry

 Signature 
Profile
 
 
Posted: 10 April 2008 06:01 PM   [ Ignore ]   [ # 2 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

I’ll give what you gave me above a try here in a few…

The reason I keep trying to use {if count == 1} for this type of situation is because over a year ago or so for my blog I had some help with showing related entries on the single entry page:

{exp:weblog:entries related_categories_mode="on" limit="5"}
   {if count
== 1}
   
<h3>Related Posts</h3>
   <
ul class="related">
   
{/if}
<li><a href="{title_permalink=blog/article}" title="{title}">{title}</a></li>
   
{if count == total_results}
   
</ul>
   
{/if}
{
/exp:weblog:entries}

The {if count == 1} is inside the weblog entries loop there but the heading only shows once even though I’m displaying 5 related entries. What is the difference between these two?

EDIT: Gave your work around a try… worked great! Thanks for the tip. I wouldn’t have thought of that on my own. Didn’t even know that was possible. wink

Profile