By default the fivestar rating widget is placed at the bottom of the node. We have the option to place it above or below the node content, but I want to place it at a custom location within the content of my node. Like I will like to place some HTML above the rating widget and some below it. How can I do it? I have enabled the php module, so I can write php code in my node content. Any ideas???
I have googled a lot for the solution but haven't found a direction. Any help will be appreciated :)

Comments

amit4uall’s picture

still stuck......need help urgently.....!!!

stanuku’s picture

$node = node_load($nid);
echo fivestar_widget_form($node);

amit4uall’s picture

thanks tayyaba for the direction :)
The code doesn't work if I post it in a php tag in my node content but it does work if i put it in my node.tpl.php file of the theme i am using.
I have devised an ugly hack but it works for me, and i am posting it here so that maybe it saves the day for someone else.

Add the following code to you node.tpl.php file:

if (user_access('rate content') && variable_get('fivestar_'. $node->type, FALSE)) {
    $fivestar_widget = fivestar_widget_form($node);
  }
else {
    $current_rating = _votingapi_get_standard_results('node', $nid);
    echo $current_rating[vote][percent][average];
    $fivestar_widget = theme_fivestar_static($current_rating[vote][percent][average]);
  }
  $content = str_replace('[STARRATINGBLOCK]', $fivestar_widget, $content);

just above the following div:
<div class="content clear-block">
<?php print $content ?>
</div>

Insert "[STARRATINGBLOCK]" in your node content, wherever you want to place the fivestar widget.
The if else block is so that only logged in users are able to vote and anonymous users are only able to see the rating.
Without it, the fivestar widget will be visible for all nodes and users.
Also remember to change the visibility setting of fivestar widget to hidden, or else it will be visible twice.

Jeff Burnz’s picture

Ok, heres a much better way, I use this here on my free themes sites - http://3rdworldthemes.org/ - just to show you this does work:)

<div class="fivestar-rating">
  <?php print $node->content['fivestar_widget']['#value']; ?>
</div>

This will respect all the internal permissions and view settings etc you give to fivestar via Drupal admin.

amit4uall’s picture

I am not sure if it works. It didn't work for me when i had set full node display to hidden in fivestar settings.
It is displayed twice if i select any other option in full node display.

I think, $node->content['fivestar_widget']['#value'] is null in case of hidden widget, and in all other cases it will be displayed twice(1 where we display it+along with the content, either below or above the node).

Jeff Burnz’s picture

I don't print the content variable, since the only real way to break up the content variable is to print each field separately (a D6 limitation, thankfully fixed in D7 very soon).

You method is a hack, whereas what I have shown is how to actually achieve it in D6, following the design of the system.

calefilm’s picture

Jeff, Where would I input the code you referred to? Which file? or directly into node content itself?

Thank you.

Jeff Burnz’s picture

It goes in node.tpl.php or your node-[content-type].tpl.php file.

As Amit4uall points out, that unless you are printing all the fields of the content type seperatly (the right way to theme node types in Drupal 6) the widget will print twice. If you dont know how to do this then install the Contemplate module as that will help you identify the other variables you need to print in your node tpl files, OR use Amit4uall's method as that will work as well and is the quick and dirty way to get this working.

calefilm’s picture

Works. Thank you.

Now I'm just trying to center the stars in the middle of my select node. I assume it's possible to center...

I appreciate the advice on your site: http://design.acquia.com/drupal-themes and think I'll look into downloading Genesis and going from there.

joeko’s picture

Hello

I have got the same problem I want to place five star widget at a custom location within the content of my node. I have added following code to you node.tpl.php file:

<div class="fivestar-rating">
  <?php print $node->content['fivestar_widget']['#value']; ?>
</div>

What should I add to node content, to make it works? Thanks for answer?

terryj1s’s picture

if (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
  print rate_embed($node, 'Your Widget Machine Name');
}

Simply add your styling and relplace Your Widget Machine Name with the Widget you created and this will work for drupal 7

calefilm’s picture

Amit4uall works but I'm trying to figure out Jeff's way...