By amit4uall on
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
still stuck......need help
still stuck......need help urgently.....!!!
Try this
$node = node_load($nid);
echo fivestar_widget_form($node);
thanks tayyaba for the
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:
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.
...
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:)
This will respect all the internal permissions and view settings etc you give to fivestar via Drupal admin.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I am not sure if it works. It
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).
...
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.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Where would i input this code?
Jeff, Where would I input the code you referred to? Which file? or directly into node content itself?
Thank you.
...
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.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks!
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.
Hello I have got the same
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:
What should I add to node content, to make it works? Thanks for answer?
Here is your answer
Simply add your styling and relplace Your Widget Machine Name with the Widget you created and this will work for drupal 7
Any help would be appreciated
Amit4uall works but I'm trying to figure out Jeff's way...