Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
sirkitree CreditAttribution: sirkitree commentedI'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()
?Comment #2
Flying Drupalist CreditAttribution: Flying Drupalist commentedHi, 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.
Comment #3
sirkitree CreditAttribution: sirkitree commentedYou 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.
Comment #4
Flying Drupalist CreditAttribution: Flying Drupalist commentedThank you sirkitree, but how would I style the count token independently of the text token?
Comment #5
sirkitree CreditAttribution: sirkitree commentedI 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.
Comment #6
mooffie CreditAttribution: mooffie commentedMiraploy, 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.
Comment #7
Flying Drupalist CreditAttribution: Flying Drupalist commentedAhh I was not aware of that, thanks mooffie.
Comment #9
nedjoCan also be done through tokens. see http://drupal.org/node/319491.
Comment #10
BenK CreditAttribution: BenK commentedJust need to track this thread...
Comment #11
FiNeX CreditAttribution: FiNeX commented...it works on comments too :-)
Comment #12
tky CreditAttribution: tky commentedIn D7 version, just copy flag.tpl.php and paste it in YOURTHEME/tamplates folder. No need to change name.
Comment #13
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedThank 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:
and then actually displaying the flag count:
Comment #14
bsarchive CreditAttribution: bsarchive commentedFantastic! Thanks. I can't imagine why this isn't built into the module as a standard display option.