Hi, I know I can get the flag count display by doing this:

$flag->get_count($content_id)

But the number doesn't display by ajax, how can I do that? Thanks.

Comments

sirkitree’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure what you mean by this. The only thing I can assume is that you are displaying a count in your flag link's text, in which case it would be more practical to use the token for the count in your flag's settings.

If I'm assuming wrong, can you please elaborate where you are trying to use $flag->get_count()?

Flying Drupalist’s picture

Hi, I'm trying to get the number of flag counts to display like digg. It's that page in the docs that I got $flag->get_count() from. So it's not in my flag text link, but close by. However I need the count to update via ajax so it looks like digg. Thanks.

sirkitree’s picture

You would have to write your own custom jQuery to handle that.

I would suggest using the token in your flag's text and then styling it to put a background image. But that's without seeing your design.

Flying Drupalist’s picture

Thank you sirkitree, but how would I style the count token independently of the text token?

sirkitree’s picture

I don't think you'd be able to style them separately as they'd be the same element. However, I think that the return text can take in a token as well and maybe that could be where you put your count, that would make it a separate element and give the ability to style it differently then the text.

mooffie’s picture

Status: Postponed (maintainer needs more info) » Fixed

Miraploy, you don't need to know anything about Ajax.

1. As theme/README.txt explains:

1.a Copy flag.tpl.php into flag-YOURFLAGFNAME.tpl.php.

1.b Move it into your theme folder.

1.c Clear Drupal's cache.

2. Put $flag->get_count($content_id) in that file. Whatever in that tpl file is fetched anew with every mouse click.

Flying Drupalist’s picture

Ahh I was not aware of that, thanks mooffie.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

nedjo’s picture

Component: Code » Flag core

Can also be done through tokens. see http://drupal.org/node/319491.

BenK’s picture

Just need to track this thread...

FiNeX’s picture

...it works on comments too :-)

tky’s picture

Version: 6.x-1.x-dev » 7.x-2.0

In D7 version, just copy flag.tpl.php and paste it in YOURTHEME/tamplates folder. No need to change name.

Nicolas Bouteille’s picture

Issue summary: View changes

Thank you for this #6.
Just wanted to precise that adding the flag machine name to flag--flag_machine_name.tpl.php instead of just flag.tpl.php is not related to D6 or D7, it just allows to only target one flag or everyone of them... Beware that just one hyphen '-' did not work for me but two '--' did in flag--like.tpl.php
Also $content_id does not work anymore, $entity_id does though.
Here's my code preparing the count:

<?php
  $flag_jaime = flag_get_flag('jaime');
  $jaime_count = $flag_jaime->get_count($entity_id);
  if ($jaime_count != 0) {
    $jaime_count = '<span class="jaime_count">' . $jaime_count . '</span>';
  }
  else {
    $jaime_count = '';
  }
?>

and then actually displaying the flag count:

<?php
<?php if ($link_href): ?>
    <a href="<?php print $link_href; ?>" title="<?php print $link_title; ?>" class="<?php print $flag_classes ?>" rel="nofollow"><?php print $link_text . $jaime_count; ?></a><span class="flag-throbber">&nbsp;</span>
  <?php else: ?>
    <span class="<?php print $flag_classes ?>"><?php print $link_text . $jaime_count; ?></span>
  <?php endif; ?>
?>
bsarchive’s picture

Fantastic! Thanks. I can't imagine why this isn't built into the module as a standard display option.