Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-01-22 08:53:21
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
rating stars
Reading an interesting article by Natalie Jost about rating articles with stars and the comment by Matthew Smith about TXP integration, I made some attempts. Unfortunately the rating stars don’t appear in my site.
The latest trick suggested by Matthew is this: making my star.gif (* * * * *) five stars wide (50×20px), and then, in my subsequent CSS, changing the position of my stars background depending on the class of the span.
css:
.star
{
background: url(http://www.maidireblog.it/textpattern/css/images/stars.gif) no-repeat 0 50%;
display:block;
height: 20px;
width: 50px;
}
custom field:
<txp:if_custom_field name="rating">
<span class="star<txp:custom_field name="rating" />"><txp:custom_field name="rating" /> stars</span>
</txp:if_custom_field>
If my custom field has a 4 in it, the span becomes span.star4
span.star1 {background-position: 10px 50%}
span.star2 {background-position: 20px 50%}
but it doesn’t work: the value in correctly reported but the stars doesn’t appear.
Where is my error? Any suggestion?
Thanks in advance,
Alessandro
Last edited by candyman (2007-01-22 08:55:28)
Offline
Re: rating stars
I just did this, which works perfectly:
<txp:if_custom_field name="rating" val="0"><img src="/images/33.gif" alt="0 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="0.5"><img src="/images/54.gif" alt="0,5 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="1"><img src="/images/34.gif" alt="1 star" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="1.5"><img src="/images/55.gif" alt="1,5 star" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="2"><img src="/images/35.gif" alt="2 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="2.5"><img src="/images/56.gif" alt="2,5 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="3"><img src="/images/36.gif" alt="3 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="3.5"><img src="/images/57.gif" alt="3,5 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="4"><img src="/images/37.gif" alt="4 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="4.5"><img src="/images/58.gif" alt="4,5 stars" /></txp:if_custom_field>
<txp:if_custom_field name="rating" val="5"><img src="/images/38.gif" alt="5 stars" /></txp:if_custom_field>
I know this may be a little over the top, using 10 different images, but it gets the job done… You can see it in action here.
…Prrrrrrrr…
Offline
Re: rating stars
…and i’m doing it like this:
<img class="rating" src="/gfx/rating/<txp:custom_field name="rating" />.gif" alt="rated <txp:custom_field name="rating" /> stars" />
Offline
#4 2007-01-22 14:12:54
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: rating stars
Thank you! They work both perfectly :)
Offline
#5 2007-01-22 14:45:55
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: rating stars
Ops… using the sthmtc’s method, even if an article has no rating, it appears the writing: “rated stars”.
I have to rate only when I write reviews, in other posts I don’t need any rating (and I leave blank the rating box): how can I avoid this?
Offline
Pages: 1