SHOW:
         |
         |
         - or go back to the newest paste.    
    | 1 | // http://pastebin.com/kHpaHQvi originally | |
| 2 | // http://www.gravityhelp.com/forums/topic/show-total-donations | |
| 3 | // usage: [donations form=37] where 37 is the form ID | |
| 4 | add_shortcode('donations', 'total_donations');
 | |
| 5 | function total_donations($atts) {
 | |
| 6 | $form_id = $atts['form']; | |
| 7 | // function to pull all the entries for one form | |
| 8 | $donations = RGFormsModel::get_leads($form_id); | |
| 9 | // start the total at zero | |
| 10 | $total = 0; | |
| 11 | // initialize a counter for the number of donations made | |
| 12 | $i = 0; | |
| 13 | // loop through all the returned results | |
| 14 |         foreach ($donations as $amount) {
 | |
| 15 | // add each donation amount to the total | |
| 16 | // change 3 here to the field ID which holds the donation amount | |
| 17 | $total += $amount[3]; | |
| 18 | // increment the counter so we know how many donations there are as well | |
| 19 | $i++; | |
| 20 | } | |
| 21 | - | // change this to your locale, or, if your locale is alreasdy defined, you can remove this line | 
| 21 | + | // change this to your locale, or, if your locale is already defined, you can remove this line | 
| 22 | setlocale(LC_MONETARY, 'en_GB'); | |
| 23 | // do some formatting and return the html output from the shortcode | |
| 24 |         $output = "We have raised " . money_format('%i', $total) . " from $i donors.";
 | |
| 25 | // just the string above will be returned. You can style it here or where you are using the shortcode | |
| 26 | return $output; | |
| 27 | } | |
| 28 | // needed for the above to process the donation shortcode in sidebar widget | |
| 29 | add_filter('widget_text', 'do_shortcode'); | 
