ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

My own rating system - displaying images

September 10, 2008 7:28am

Subscribe [2]
  • #1 / Sep 10, 2008 7:28am

    wizs

    35 posts

    Hello,

    I want to rate posts myself and display a star rating (so I’ve been told I don’t need any add ons for this as it’s just me setting the rating score).

    Apparantely, I’m to create a custom field, e.g. a dropdown with values from 1 to 5, set that when posting and then display the images.

    I have created a custom field drop down, but I don’t know how to display images in the template using this drop down as a basis for whichever star image it corresponds to.

    Any pointers would be great because I’m “nearly there” with what I want to do!

  • #2 / Sep 10, 2008 8:52am

    Sean C. Smith

    3818 posts

    Try this where {rating} is your field name. You’ll also need to change http://domain.com/ to your own domain.

    {if rating ==""}
    {if rating =="1"}
        <a href="http://domain.com/1star.png">http://domain.com/1star.png</a>
    {if:elseif rating =="2"}
        <a href="http://domain.com/2star.png">http://domain.com/2star.png</a>
    {if:elseif rating =="3"}
        <a href="http://domain.com/3star.png">http://domain.com/3star.png</a>
    {if:elseif rating =="4"}
        <a href="http://domain.com/4star.png">http://domain.com/4star.png</a>
    {if:else rating =="5"}
        <a href="http://domain.com/5star.png">http://domain.com/5star.png</a>
    {/if}
    {/if}

    I just whipped this up off the cuff so it’s not guaranteed to work.

  • #3 / Sep 10, 2008 9:36am

    wizs

    35 posts

    Thanks for your help and nice idea. I’ve given it a try but to no avail (the page didn’t load). I don’t know whether that’s because there’s a syntax error? I’ve checked my fields and it was already set as {rating}

    Can anyone run their eyes over the code just to check it?

  • #4 / Sep 10, 2008 9:46am

    silenz

    1651 posts

    Easier:

    {if rating}
        <a href="http://domain.com/{rating}star.png">http://domain.com/{rating}star.png</a>
    {/if}
  • #5 / Sep 10, 2008 9:59am

    Robin Sowell

    13255 posts

    wizs- does silenz’s approach work for you?  It should.  Only think you need to watch is to make sure tat the rating field’s formatting is set to ‘none’ and it should be fine.

    In truth, I didn’t spot the error in the first example, aside from the first if should be !=.  Though can’t see why it would throw an error as is.  Still- try the simplified version.  Any luck?

  • #6 / Sep 10, 2008 10:04am

    wizs

    35 posts

    Thanks so much. That’s brill! This is probably the most helpful forum I’ve ever posted in. Thanks once again.

  • #7 / Sep 10, 2008 10:16am

    wizs

    35 posts

    Didn’t see your reply there Robin. Just to clarify…the simpler approach seems to be working, and I’m all for keeping things simple!

  • #8 / Sep 10, 2008 10:24am

    Robin Sowell

    13255 posts

    😉  Simple is good.  Glad silenz got you squared away!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases