Hello, I've just added this module and think it's perfect for my needs. I just wanted something to act as a "like" button in Facebook, and this does the job with thumb up.

My coding skills aren't that great, and was wondering if I could get some tips on how to integrate it with advanced forums so that the thumbs up widget appears at the foot of the post near the reply buttons, and not the body (is it does if you select 'below content'). And that you can also view the rating for a topic from the forum category display next to each post.

Thanks, I know it's asking a bit but I think it would help a lot of basic needs of some noobs like me.

Members fund testing for the Drupal project. Drupal Association Learn more


garfaldo’s picture

I'm really trying to solve this on my own, but I honestly am just not that good with coding yet. I noticed in my forum-topic-list.tpl.php file there is a line which prints something like views here.

print $topic->views_count;

I've tried changing it to

print $topic->rate_thumbUp['#value'];

But it doesn't seem to be working out. Am I missing something? That's one part of what I'm trying to do (get the thumb count in line with the topic in forum view), the other is get the rating widget to appear next to reply buttons and such.

mauritsl’s picture

That should work in your template. Is the name "thumbUp" correct? You can check that at node/123/devel/render when you have the devel module installed. And make sure that the display setting in the widget configuration is set to "Do not add automatically".

When you have that working, you can use the following code to get the widget by the node id, so you can use it anywhere you like:

$node = node_load($nid);
node_invoke_nodeapi($node, 'view');
print $topic->rate_thumbUp['#value']; 
garfaldo’s picture

Thanks so much for the reply mauritsl. I made the changes but...

Unfortunately it still doesn't work. Changed the file, made sure it was uploaded to the correct theme I'm using... still no luck. I installed devel and went to the topic list node with /devel/render appended... but not sure what I was supposed to see. Maybe I have some configurations wrong. Here is the code I have. Is there something I'm supposed to define first, or are the variables for rate usable by any node freely?

 <?php foreach ($topics as $topic): ?>
    <tr class="<?php print $topic->zebra;?>">
      <td class="title">
      	<div class="icon"><?php print $topic->icon; ?></div>
      	<?php print $topic->title; ?>
      	<div class="created"><?php print $topic->created; ?></div>
    <?php if ($topic->moved): ?>
      <td colspan="3"><?php print $topic->message; ?></td>
    <?php else: ?>
      <td class="replies">
        <?php print $topic->num_comments; ?>
        <?php if ($topic->new_replies): ?>
          <br />
          <a href="<?php print $topic->new_url; ?>"><?php print $topic->new_text; ?></a>
        <?php endif; ?>
      <td class="rating"><?php print $topic->rate_thumbup['#value']; ?></td> 
      <td class="views"><?php print $topic->views_count; ?></td>
      <td class="last-reply"><?php print $topic->last_reply; ?></td>
    <?php endif; ?>
  <?php endforeach; ?>
walker2238’s picture

Just adding my two cents here. I don't use forums but to my knowledge forums use comments do they not?

If thats the case to print the voting widget manually in comments use $comment->rate_NAMEOFWIDGET.

So maybe you can try $topic->rate_thumbUp.

Also thanks mauritsl for this module. I do hope it becomes the main voting module for Drupal.

garfaldo’s picture


They already do add themselves to comments when the option is selected in admin. What I'm trying to do is custom theme it so that it's on a specific place in the comment field (preferably right next to the reply, delete, edit options. When it's in the comment body, it almost seems as if it's part of the user's own writing. I know if you are not using a border style forum theme it probably doesn't seem that way, but unfortunately mine is.

I too love this module. It's the closest thing to a simple "like" feature in Facebook.

walker2238’s picture

I don't add the widget to comments automatically, I like to have more control over where it is placed. Thus I use $comment->rate_NAMEOFWIDGET in the comment.tpl. I figured forum threads would be the same thing. Sorry it didn't work.

BTW, if your looking for "Like" type feature flag might be best suited for you...

dreamdust’s picture

Title: Forum integration » Add widget to node/comment $links

You're not talking about integrating it with advanced forum. You're talking about adding the widget to comment $links. This must be done via hook_link(). The "reply, delete, edit" links are part of the comment $links array.

dreamdust’s picture

Version: 6.x-1.0-beta5 » 6.x-1.0
Component: Miscellaneous » Code
Category: support » feature
2.79 KB

I also needed my widget to be in node/comment links, and because I love this module so much I've created a patch to add an option to display widgets in node/comment links.

I've tested it and everything works without problem, so if someone else could test it out then the maintainer can add this into the next release.

After applying the patch, you'll see a new option called "Links" under the "Display Settings" fieldset on the "Edit widget" settings page.

dreamdust’s picture

I'm very sorry, but the last patch had a mistake in it. This one should be correct.

christefano’s picture

Status: Active » Needs work

Patch doesn't apply but the code is sound. Please reroll and mark "needs review".

bertboerland’s picture

thanks all!

mauritsl’s picture

Status: Needs work » Patch (to be ported)

Commited to git for D6.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Needs to be ported to D7.

mmilano’s picture

Version: 6.x-1.0 » 7.x-1.x-dev
Status: Patch (to be ported) » Needs review
10.77 KB

Working on the Drupal Commons sprint at SAND Camp today. We needed the rate widget in node links and ported it to D7.

The patch adds functionality and a display option to the admin form for displaying the widget in the node links.

My IDE is setup to remove trailing white space, which is all the empty fields. That is what all the lines that don't appear to be changed in the patch are.

ezra-g’s picture

Status: Needs review » Needs work

After some testing #13 wasn't displaying the Rate module node links in AdaptiveTheme but did display in Garldand. I believe we want to set:

$node->content['links']['rate']['#theme'] = 'links';
$node->content['links']['rate']['#attributes'] = array('class' => array('links', 'inline'));

Similar to how other modules such as Flag do when placing node links.

ezra-g’s picture

Status: Needs work » Needs review
5.88 KB

Re-roll per #14.

stupiddingo’s picture

Reviewing the patch in #15, discovered that the new display option wasn't included in the admin screen.

Attached patch includes #15 and addition of RATE_DISPLAY_IN_LINKS to rate.admin.inc options.

Just now noticed the prior D6 patch from #9 called this item simply "Links" where I settled on "In the links section"... truthfully, both are pretty confusing for a site builder. Naming things is hard.

stupiddingo’s picture

Issue summary: View changes
1.69 KB

Updating this patch to have links label in admin interface match title used in Rate-6.x, "Within the Links".

Also tested patch against latest Rate-7.x-1.x. Still applies cleanly and operates correctly.

thermador’s picture

Thanks for the patch! I have tested it using the latest Rate-7.x-1.x-dev, and made the changes by hand (pretty easy stuff) then disabled and re-enabled the module.

I am using Advanced Forum and AdaptiveTheme, like #14.

With this patch, I get the widget displaying in the links on the first post (the node). Yay! But the widget still displays in the main body of the replies (the comments) - not in the links.

So for me, it only works for the node, even though I have the display setting set to "Within the Links" for both Node and Comment.

This seems weird to me, as Advanced Forum's post.tpl.php file (which is used for both nodes and comments) just has this:

    <div class="forum-post-links">
      <?php print render($content['links']); ?>

so it *should* be working...

stupiddingo’s picture

Good catch thermador I wasn't even thinking about rating comments!

Now reviewing the issue I see dreamdust in #9 included a patch for D6 with rate comments. The attached patch also includes the additions by ezra-g in #15 for both nodes and comments.

I'm still noticing there is some differences between how different themes render the rate widget in links. Bartik in particular has some odd floats when the rate widget is placed in the links section.

SocialNicheGuru’s picture

I got this error when using this patch: https://drupal.org/node/2286751

Fidelix’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this works as expected. The error reported by @SocialNicheGuru is probably related to something else.

BTW, my comments are loaded via Ajax (custom implementation) as well, and even after several interactions and new comments being posted it works as expected.