Is there a shortcode to display an autoupdated list of donors for a fundraiser campaign?

Hello all,

Is there a shortcode to display an autoupdated list of donors for a fundraiser campaign?

The idea is to automatically feature and publically acknowledge donors in real time as they make their donations.

If such a feature is not present, then I recommend adding it along with a user selectable option during the donation payment process so the user can choose for their donation to be posted in the public list of donors or be listed as an anonymous donation.

This feature would provide real-time public recognition for those who support a fundraiser and could encourage increased donations where one supporter issues a friendly "challenge" for others to match their donation. Public visibility of both donor's donations could help drive fundraising activity and it would all happen automatically with these features.

Phil D

  • PC
    • WPMU DEV Initiate

    Hey Phil,

    Is there a shortcode to display an autoupdated list of donors for a fundraiser campaign?

    Currently its not possible am afraid, however I read your post carefully and found that this is really a nice feature to add in future plugin releases and I will right away move this thread to the right category and also tag our Lead developer @Cole on this thread so that we can have his views on it too.

    Thanks a lot for taking time and sharing this with us.

    Cheers
    PC

  • bhuskilson
    • Flash Drive

    Hey Phil,

    I've been able to do what you describe with the code below. I've placed it in single.php. If you customize it a bit, you should be able to get the look you want. In the code, I have it set to only show the first initial of the last name, but you could remove that. I have not been able to get the opt in/out to work yet but I hope to.

    // If the fundraiser exists and fundraising is installed then continue
    if(get_post($post_id) && class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    	$pledge_list = $wdf->get_pledge_list($post_id);
    	if ($pledge_list) {
    	foreach($pledge_list as $pledge) {
    		// get_transaction() returns an array of available transaction meta-data;
    		$transaction = $wdf->get_transaction($pledge->ID);
    		//This prints the transaction array so you can see what is available for display.
    		// echo '<pre>'.var_export($transaction,true).'</pre>';
    		$lname = $transaction['last_name'];
    		echo '<div class="supporter">'.$transaction['first_name'].' '.$lname[0].'. $'.$transaction['gross'].'</div>';
    	}
    	}
    }

    If you un-comment this line you can see the variables you have available.

    // echo '<pre>'.var_export($transaction,true).'</pre>';

    I also have a custom widget that keeps a list of the top funders in each campaign and orders them in a sort of "leader board".

    I can share that code as well if you like.

  • SooBahkDo
    • Syntax Hero

    Hello bhuskilson,

    Thanks for sharing. I would like the widget you mention with full first and last name displaying.

    Cole, please do work up a shortcode.

    [High Priority] Please implement a "search" that works. Currently it is not possible to search pledge transactions for those related to a search term. This compounds the next challenges associated with having no export capability.

    [High Priority] While you are at it, please add pledge transaction exporting to xcel or csv. That is badly needed for reconciliation purposes. The person using the plugin is crying the blues that they cannot export the pledge transactions to a spreadsheet so they can reconcile against their PayPal and bank accounts. It is a pain when the qty of pledge entries gets long.

    Manual code edits are difficult for us to manage on a multisite installation.

    Thanks for the code and I look forward to the widget. It would be great if it were also bundled into the core plugin... hint...hint... :slight_smile:

    Thanks
    Phil D

  • bhuskilson
    • Flash Drive

    So here's the widget code. It was important to us that people get ranked in the same position if they have the same amount so I'm grouping them.

    <?php
    /*
    Plugin Name: Top Funders Widget
    Plugin URI: http://huskor.com/
    Description: Selects highest contributions from WPMU Dev's fundraising script.
    Author: Bryce Huskilson
    Version: 1
    Author URI: http://huskor.com/
    */
    
    class TopFundersWidget extends WP_Widget
    {
      function TopFundersWidget()
      {
        $widget_ops = array('classname' => 'TopFundersWidget', 'description' => 'Displays top contributions from WPMUDEV fundraising script' );
        $this->WP_Widget('TopFundersWidget', 'Top Funders List', $widget_ops);
      }
    
      function form($instance)
      {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
        $title = $instance['title'];
    ?>
      <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
    <?php
      }
    
      function update($new_instance, $old_instance)
      {
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        return $instance;
      }
    
      function widget($args, $instance)
      {
        extract($args, EXTR_SKIP);
    
        echo $before_widget;
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    
        if (!empty($title))
          echo $before_title . $title . $after_title;;
    
        // WIDGET CODE GOES HERE
    
    	global $wp_query;
    
    // If fundraising is installed then continue
    if(class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    
    	if(get_post($post_id)) {
    		$pledge_list = $wdf->get_pledge_list($post_id);
    		}
    	else
    		{
    		$pledge_list = $wdf->get_pledge_list();
    		}
    
    	if ($pledge_list) {
    
    	$pledgesort = array();
    	// Build array to compare email accounts
    	foreach($pledge_list as $pledge) {
    		$transaction = $wdf->get_transaction($pledge->ID);
    
    		$lname = $transaction['last_name'];
    		$pledgesortdata = array(
    		'name' => $transaction['first_name'].' '.$lname[0],
    		'amount' => intval(preg_replace('~\.0+$~','',$transaction['gross'])),
    		'email' => $transaction['payer_email']
    		);
    
    		$pledgesort[] = $pledgesortdata;
    	}
    
    	// Function to group donation by paypal email address
    	function arraySort($input,$sortkey){
    	  foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
    	  return $output;
    	}
    	$pledgesort = arraySort($pledgesort,'email');
    
    	$backerlist = array();
    	foreach($pledgesort as $backeremail) {
    
    			$amount = 0;
    			foreach($backeremail as $key) {
    				$amount = $amount + $key['amount'];
    			}
    
    		$backerlistdata = array(
    		'name' => $key['name'],
    		'amount' => $amount,
    		'email' => $key['email']
    		);
    		$backerlist[] = $backerlistdata;
    
    	}
    
    	$backerlist = arraySort($backerlist,'amount');
    
    	krsort($backerlist);
    
    	$backerlist = array_slice($backerlist, 0, 10);	
    
    	//print_r($backerlist);
    
    	echo '<div id="topbackers">
    	<span class="homehilight" style="float:right; margin-right:20px;">
        Total Funded</span>
    	<div style="clear:both"></div>
    	<div id="backerscroll" style="overflow:auto; height:150px">
      <ul>
    	';
    	$fan = 0;
    	foreach($backerlist as $backer) {
    		$fan = $fan + 1;
    
    		echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';
    		$i = 0;
    		foreach($backer as $key) {
    		echo '<div>'.$key['name'].' ';
    		echo ' <span style="float:right; margin-right:5px;">$'.$key['amount'].'</span></div>';
    		}
    		echo '</li>';
    
    	}
    	echo '</ul></div></div>';
    	}
    
    }
    
        echo $after_widget;
      }
    
    }
    add_action( 'widgets_init', create_function('', 'return register_widget("TopFundersWidget");') );?>

    As you can see I've cheated a little and done some styling inline. Not ideal, but it's a work in progress.

    If you want to show the full last name just change this line

    'name' => $transaction['first_name'].' '.$lname[0],

    to this

    'name' => $transaction['first_name'].' '.$lname,

    Play around a bit and let me know if you have any questions.

  • Cole
    • The Incredible Code Injector

    @SooBahkDo
    Great call. Easily done.

    @bhuskilson
    I really like this widget idea for the BuddyPress component being developed. Would you be alright letting me try and work it into a future release along with the shortcode?

  • SooBahkDo
    • Syntax Hero

    Hello,

    Just installed the widget on our site and am wondering about the results displayed

    I know we have a donor who gave $2,500 as the 1st donation in this campaign, but the highest one displayed is a more recent $800 donor.

    Are the results time frame dependent? or transaction type dependent?

    I would provide a link to the site, but I disabled the widget since the top donor was not displaying.

    Ideas?

    Phil D

  • SooBahkDo
    • Syntax Hero

    Hi Cole,

    Thanks for the exporting tip.

    I vote that it would also be great to have an export button in the plugin controls to minimize user error in configuring the export results.

    We are giving the plugin a workout and it's chugging along flawlessly. :slight_smile:

    Phil D

  • bhuskilson
    • Flash Drive

    If the widget is displayed on the home page it should grab the highest from all fundraisers. If it is displayed on a fundraiser page, it will display only pledges from that fundraiser. Is this perhaps the issue?

    Does the donation you are referring to show up in the donations list in the back end?

  • SooBahkDo
    • Syntax Hero

    Hello bhuskilson,

    You cleared up part of it for me.

    The $2500 was on one and the $800 was on a different fundraiser.

    Works great on this sidebar with this label
    http://soobahkdofoundation.org/fundraisers/region-8-fundraising-2012/

    I want to lengthen the display a bit and change the labels from Fan to Donors and may be able to figure that out. I'll give it a shot.

    Cole, for the incorporated widget, I would like to see user configuration entries for the apx number of donors displayed in the widget (or pixel height of the display - Like the Live Stream Widget) and user configurable Grouping label. [same for the shortcode]

    This will be a great addition to the plugin and I think displaying a page or post listing via shortcode of donors will increase donations.

    FYI: However, when the widget is on the Homepage sidebar I cannot get it to display any results.

    Thanks for the assist! :slight_smile:

    Phil D

  • bhuskilson
    • Flash Drive

    Yes, I got lazy and hard coded some styles. For height and scroll, change this line.

    <div id="backerscroll" style="overflow:auto; height:150px">

    and for Fan you'll want to change this line.

    echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';

  • rchidalgo
    • WPMU DEV Initiate

    Pardon my "noobiness" but, @bhuskilson, for the first set of code that you posted in single.php, does this go inside 'The Loop" or does this replace "The Loop" completely?

    It seems to me that this code is a loop in and of itself, but I can't seem to get it to work on my site after I copied this code to a page template inside a <?php ... ?> tag.

    Thanks in advance. :slight_smile:

  • claudette
    • WPMU DEV Initiate

    Placed inside the loop in Single.php, the code works for me (sorry for the brief explanation but I'm also a noobi).

    I tweaked it to list full names and no amounts and it's fantastic! Thanks for the code!

    Is there any way to give donors the option to remain anonymous?

  • PC
    • WPMU DEV Initiate

    Hiya @claudette

    Greetings and thanks for posting on the forums.

    I will suggest and really appreciate if you could open a new thread if you still have questions on this one. This is quite an old thread and originally created for a different issue.

    Cheers, PC

  • bhuskilsonVLC
    • WPMU DEV Initiate

    This chunk should work in your post template. I have created a single-funder.php file in my theme for this.

    // If fundraising is installed then continue
    if(class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    
    	if(get_post($post_id)) {
    		$pledge_list = $wdf->get_pledge_list($post_id);
    		}
    	else
    		{
    		$pledge_list = $wdf->get_pledge_list();
    		}
    
    	if ($pledge_list) {
    
    	$pledgesort = array();
    	// Build array to compare email accounts
    	foreach($pledge_list as $pledge) {
    		$transaction = $wdf->get_transaction($pledge->ID);
    
    		$lname = $transaction['last_name'];
    		$pledgesortdata = array(
    		'name' => $transaction['first_name'].' '.$lname[0],
    		'amount' => intval(preg_replace('~\.0+$~','',$transaction['gross'])),
    		'email' => $transaction['payer_email']
    		);
    
    		$pledgesort[] = $pledgesortdata;
    	}
    
    	// Function to group donation by paypal email address
    	function arraySort($input,$sortkey){
    	  foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
    	  return $output;
    	}
    	$pledgesort = arraySort($pledgesort,'email');
    
    	$backerlist = array();
    	foreach($pledgesort as $backeremail) {
    
    			$amount = 0;
    			foreach($backeremail as $key) {
    				$amount = $amount + $key['amount'];
    			}
    
    		$backerlistdata = array(
    		'name' => $key['name'],
    		'amount' => $amount,
    		'email' => $key['email']
    		);
    		$backerlist[] = $backerlistdata;
    
    	}
    
    	$backerlist = arraySort($backerlist,'amount');
    
    	krsort($backerlist);
    
    	$backerlist = array_slice($backerlist, 0, 10);	
    
    	//print_r($backerlist);
    
    	echo '<div id="topbackers">
    	<span class="homehilight" style="float:right; margin-right:20px;">
        Total Funded</span>
    	<div style="clear:both"></div>
    	<div id="backerscroll" style="overflow:auto; height:150px">
      <ul>
    	';
    	$fan = 0;
    	foreach($backerlist as $backer) {
    		$fan = $fan + 1;
    
    		echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';
    		$i = 0;
    		foreach($backer as $key) {
    		echo '<div>'.$key['name'].' ';
    		echo ' <span style="float:right; margin-right:5px;">$'.$key['amount'].'</span></div>';
    		}
    		echo '</li>';
    
    	}
    	echo '</ul></div></div>';
    	}
    
    }
  • Jade
    • The Incredible Code Injector

    sorry to keep asking questions so Ill crete a new single.php called single-funder.php then drop then code where I want it to appear on the post page like if I want it bellow the comments drop it bellow the comments section with in the single-funder.php is that correct?

  • Jade
    • The Incredible Code Injector

    I think I may have gone wrong somewhere the code worked fine on one theme but not on woo theme canvas for some reason code used is bellow not sure what I've done differently

    <?php
    /**
     * Single Post Template
     *
     * This template is the default page template. It is used to display content when someone is viewing a
     * singular view of a post ('post' post_type).
     * @link http://codex.wordpress.org/Post_Types#Post
     *
     * @package WooFramework
     * @subpackage Template
     */
    
    get_header();
    ?>
    
        <!-- #content Starts -->
    	<?php woo_content_before(); ?>
        <div id="content" class="col-full">
    <div id="funderdetails">
    // If fundraising is installed then continue
    if(class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    
    	if(get_post($post_id)) {
    		$pledge_list = $wdf->get_pledge_list($post_id);
    		}
    	else
    		{
    		$pledge_list = $wdf->get_pledge_list();
    		}
    
    	if ($pledge_list) {
    
    	$pledgesort = array();
    	// Build array to compare email accounts
    	foreach($pledge_list as $pledge) {
    		$transaction = $wdf->get_transaction($pledge->ID);
    
    		$lname = $transaction['last_name'];
    		$pledgesortdata = array(
    		'name' => $transaction['first_name'].' '.$lname[0],
    		'amount' => intval(preg_replace('~\.0+$~','',$transaction['gross'])),
    		'email' => $transaction['payer_email']
    		);
    
    		$pledgesort[] = $pledgesortdata;
    	}
    
    	// Function to group donation by paypal email address
    	function arraySort($input,$sortkey){
    	  foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
    	  return $output;
    	}
    	$pledgesort = arraySort($pledgesort,'email');
    
    	$backerlist = array();
    	foreach($pledgesort as $backeremail) {
    
    			$amount = 0;
    			foreach($backeremail as $key) {
    				$amount = $amount + $key['amount'];
    			}
    
    		$backerlistdata = array(
    		'name' => $key['name'],
    		'amount' => $amount,
    		'email' => $key['email']
    		);
    		$backerlist[] = $backerlistdata;
    
    	}
    
    	$backerlist = arraySort($backerlist,'amount');
    
    	krsort($backerlist);
    
    	$backerlist = array_slice($backerlist, 0, 10);	
    
    	//print_r($backerlist);
    
    	echo '<div id="topbackers">
    	<span class="homehilight" style="float:right; margin-right:20px;">
        Total Funded</span>
    	<div style="clear:both"></div>
    	<div id="backerscroll" style="overflow:auto; height:150px">
      <ul>
    	';
    	$fan = 0;
    	foreach($backerlist as $backer) {
    		$fan = $fan + 1;
    
    		echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';
    		$i = 0;
    		foreach($backer as $key) {
    		echo '<div>'.$key['name'].' ';
    		echo ' <span style="float:right; margin-right:5px;">$'.$key['amount'].'</span></div>';
    		}
    		echo '</li>';
    
    	}
    	echo '</ul></div></div>';
    	}
    
    }
    </div>
        	<div id="main-sidebar-container">    
    
                <!-- #main Starts -->
                <?php woo_main_before(); ?>
                <section id="main">
    <?php
    	woo_loop_before();
    
    	if (have_posts()) { $count = 0;
    		while (have_posts()) { the_post(); $count++;
    
    			woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.
    		}
    	}
    
    	woo_loop_after();
    ?>     
    
                </section><!-- /#main -->
                <?php woo_main_after(); ?>
    
                <?php get_sidebar(); ?>
    
    		</div><!-- /#main-sidebar-container -->         
    
    		<?php get_sidebar('alt'); ?>
    
        </div><!-- /#content -->
    	<?php woo_content_after(); ?>
    
    <?php get_footer(); ?>
  • Jade
    • The Incredible Code Injector

    hi there im trying to figure this out properly i need the section to appear above the coments section this is the code with out the php added

    <?php
    /**
     * Single Post Template
     *
     * This template is the default page template. It is used to display content when someone is viewing a
     * singular view of a post ('post' post_type).
     * @link http://codex.wordpress.org/Post_Types#Post
     *
     * @package WooFramework
     * @subpackage Template
     */
    
    get_header();
    ?>
    
        <!-- #content Starts -->
    	<?php woo_content_before(); ?>
        <div id="content" class="col-full">
    
        	<div id="main-sidebar-container">    
    
                <!-- #main Starts -->
                <?php woo_main_before(); ?>
                <section id="main"> 
    
    <?php
    	woo_loop_before();
    
    	if (have_posts()) { $count = 0;
    		while (have_posts()) { the_post(); $count++;
    
    			woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.
    		}
    	}
    
    	woo_loop_after();
    ?> 
    
                </section><!-- /#main -->
                <?php woo_main_after(); ?>
    
                <?php get_sidebar(); ?>
    
    		</div><!-- /#main-sidebar-container -->         
    
    		<?php get_sidebar('alt'); ?>
    
        </div><!-- /#content -->
    	<?php woo_content_after(); ?>
    
    <?php get_footer(); ?>

    and with the code added but when its here it appears bellow the coments

    I need it above the comments not bellow

    <?php
    /**
     * Single Post Template
     *
     * This template is the default page template. It is used to display content when someone is viewing a
     * singular view of a post ('post' post_type).
     * @link http://codex.wordpress.org/Post_Types#Post
     *
     * @package WooFramework
     * @subpackage Template
     */
    
    get_header();
    ?>
    
        <!-- #content Starts -->
    	<?php woo_content_before(); ?>
        <div id="content" class="col-full">
    
        	<div id="main-sidebar-container">    
    
                <!-- #main Starts -->
                <?php woo_main_before(); ?>
                <section id="main"> 
    
    <?php
    	woo_loop_before();
    
    	if (have_posts()) { $count = 0;
    		while (have_posts()) { the_post(); $count++;
    
    			woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.
    		}
    	}
    
    	woo_loop_after();
    ?>
    <!--#funder details starts -->
    <?php
    global $wp_query;
    
    // If fundraising is installed then continue
    if(class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    
    	if(get_post($post_id)) {
    		$pledge_list = $wdf->get_pledge_list($post_id);
    		}
    	else
    		{
    		$pledge_list = $wdf->get_pledge_list();
    		}
    
    	if ($pledge_list) {
    
    	$pledgesort = array();
    	// Build array to compare email accounts
    	foreach($pledge_list as $pledge) {
    		$transaction = $wdf->get_transaction($pledge->ID);
    
    		$lname = $transaction['last_name'];
    		$pledgesortdata = array(
    		'name' => $transaction['first_name'].' '.$lname[0],
    		'amount' => intval(preg_replace('~\.0+$~','',$transaction['gross'])),
    		'email' => $transaction['payer_email']
    		);
    
    		$pledgesort[] = $pledgesortdata;
    	}
    
    	// Function to group donation by paypal email address
    	function arraySort($input,$sortkey){
    	  foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
    	  return $output;
    	}
    	$pledgesort = arraySort($pledgesort,'email');
    
    	$backerlist = array();
    	foreach($pledgesort as $backeremail) {
    
    			$amount = 0;
    			foreach($backeremail as $key) {
    				$amount = $amount + $key['amount'];
    			}
    
    		$backerlistdata = array(
    		'name' => $key['name'],
    		'amount' => $amount,
    		'email' => $key['email']
    		);
    		$backerlist[] = $backerlistdata;
    
    	}
    
    	$backerlist = arraySort($backerlist,'amount');
    
    	krsort($backerlist);
    
    	$backerlist = array_slice($backerlist, 0, 10);	
    
    	//print_r($backerlist);
    
    	echo '<div id="topbackers">
    	<span class="homehilight" style="float:right; margin-right:20px;">
        Total Funded</span>
    	<div style="clear:both"></div>
    	<div id="backerscroll" style="overflow:auto; height:150px">
      <ul>
    	';
    	$fan = 0;
    	foreach($backerlist as $backer) {
    		$fan = $fan + 1;
    
    		echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';
    		$i = 0;
    		foreach($backer as $key) {
    		echo '<div>'.$key['name'].' ';
    		echo ' <span style="float:right; margin-right:5px;">$'.$key['amount'].'</span></div>';
    		}
    		echo '</li>';
    
    	}
    	echo '</ul></div></div>';
    	}
    
    }
    ?>
    <!-- /#funder details end --> 
    
                </section><!-- /#main -->
                <?php woo_main_after(); ?>
    
                <?php get_sidebar(); ?>
    
    		</div><!-- /#main-sidebar-container -->         
    
    		<?php get_sidebar('alt'); ?>
    
        </div><!-- /#content -->
    	<?php woo_content_after(); ?>
    
    <?php get_footer(); ?>
  • Eric
    • New Recruit

    okay, so I have created a new file called single-funder.php and put it under my theme folder. what's the next step after this? how do I call this single-funder.php file to display the list of donors - @jade and @bhuskilsonVLC

    <?php get_header(); ?>
    <?php
    $post_layout = (get_post_meta(get_the_ID(), SHORTNAME . "_post_layout", true)) ? get_post_meta(get_the_ID(), SHORTNAME . "_post_layout", true) : 'layout_'.get_option(SHORTNAME . '_post_layout').'_sidebar';
    $post_sidebar = (get_post_meta(get_the_ID(), SHORTNAME . '_post_sidebar', true)) ? get_post_meta(get_the_ID(), SHORTNAME . '_post_sidebar', true) : get_option(SHORTNAME . '_post_sidebar');
    ?>
    <div id="contentarea" class="row">
    	<?php if ($post_layout == 'layout_left_sidebar') { ?>
    	<aside class="grid_4 left-sidebar">
    		<?php $sidebar = ($post_sidebar)? $post_sidebar : "default-sidebar";
    		generated_dynamic_sidebar_th($sidebar); ?>
    	</aside>
    	<?php } ?>
    	<div class="<?php echo ($post_layout == 'layout_none_sidebar') ? 'grid_12' : 'grid_8'; ?>">
    		<?php get_template_part('loop'); ?>
    	</div>
    	<?php if ($post_layout == 'layout_right_sidebar') { ?>
    	<aside class="grid_4 right-sidebar">
    		<?php $sidebar = ($post_sidebar)? $post_sidebar : "default-sidebar";
    		generated_dynamic_sidebar_th($sidebar); ?>
    	</aside>
    	<?php } ?>
    
    	<?php
    	// If fundraising is installed then continue
    	if(class_exists('WDF')) {
    		global $wdf;
    		// get_pledge_list() returns standard array() of post objects
    
    		if(get_post($post_id)) {
    			$pledge_list = $wdf->get_pledge_list($post_id);
    		}
    		else {
    		$pledge_list = $wdf->get_pledge_list();
    		}
    		if ($pledge_list) {
    
    		$pledgesort = array();
    		// Build array to compare email accounts
    		foreach($pledge_list as $pledge) {
    			$transaction = $wdf->get_transaction($pledge->ID);
    
    			$lname = $transaction['last_name'];
    			$pledgesortdata = array(
    			'name' => $transaction['first_name'].' '.$lname[0],
    			'amount' => intval(preg_replace('~\.0+$~','',$transaction['gross'])),
    			'email' => $transaction['payer_email']
    			);
    
    			$pledgesort[] = $pledgesortdata;
    		}
    
    		// Function to group donation by paypal email address
    		function arraySort($input,$sortkey){
    		foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
    			return $output;
    		}
    		$pledgesort = arraySort($pledgesort,'email');
    
    		$backerlist = array();
    		foreach($pledgesort as $backeremail) {
    			$amount = 0;
    			foreach($backeremail as $key) {
    				$amount = $amount + $key['amount'];
    			}
    
    			$backerlistdata = array(
    			'name' => $key['name'],
    			'amount' => $amount,
    			'email' => $key['email']
    			);
    			$backerlist[] = $backerlistdata;
    		}
    		$backerlist = arraySort($backerlist,'amount');
    
    		krsort($backerlist);
    
    		$backerlist = array_slice($backerlist, 0, 10);	
    
    		//print_r($backerlist);
    
    		echo '<div id="topbackers">
    		<span class="homehilight" style="float:right; margin-right:20px;">
    		Total Funded</span>
    		<div style="clear:both"></div>
    		<div id="backerscroll" style="overflow:auto; height:150px">
    		<ul>
    		';
    		$fan = 0;
    		foreach($backerlist as $backer) {
    			$fan = $fan + 1;
    
    			echo '<li><span class="homehilight"># '.$fan.' Fan Spot:</span><br />';
    			$i = 0;
    			foreach($backer as $key) {
    				echo '<div>'.$key['name'].' ';
    				echo ' <span style="float:right; margin-right:5px;">$'.$key['amount'].'</span></div>';
    			}
    			echo '</li>';
    		}
    		echo '</ul></div></div>';
    	}
    
    	?>
    </div>
    <?php get_footer(); ?>
  • bhuskilsonVLC
    • WPMU DEV Initiate

    @Eric

    Wordpress automatically calls single-funder.php instead of single.php because of its name.

    Check our the Wordpress template hierarchy for more info on this

    What I did was create a duplicate of my single.php and called it single-funder.php.

    Depending on what you want to appear, you can place some of the above code into this file to have it call a list of funders.

    If you just want a list of people who have contributed, you can place this code somewhere

    // If the fundraiser exists and fundraising is installed then continue
    if(get_post($post_id) && class_exists('WDF')) {
    	global $wdf;
    	// get_pledge_list() returns standard array() of post objects
    	$pledge_list = $wdf->get_pledge_list($post_id);
    	if ($pledge_list) {
    	foreach($pledge_list as $pledge) {
    		// get_transaction() returns an array of available transaction meta-data;
    		$transaction = $wdf->get_transaction($pledge->ID);
    		//This prints the transaction array so you can see what is available for display.
    		// echo '<pre>'.var_export($transaction,true).'</pre>';
    		$lname = $transaction['last_name'];
    		echo '<div class="supporter">'.$transaction['first_name'].' '.$lname[0].'. $'.$transaction['gross'].'</div>';
    	}
    	}
    }

    You can also uncomment this line to see other variable that are available.

    // echo '<pre>'.var_export($transaction,true).'</pre>';

    In the example above, we didn't want to print the full last name so I am trimming it and just printing their last initial.

    There is also code above that will print just the top funders so you can have a "leader board". This can be installed and used as a widget or placed into your single-funder.php page in your template.

    Hope this helps.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.