Kiva Loans WordPress Widget
This is the Kiva Loans WordPress Widget page, which includes the technical details and instructions for the widget. Please direct any questions or comments to the comments of this post. If you would like to read about my experience in building the Kiva.org Loans Widget, please read this post.
Kiva.org Loans Widget Description
Kiva Loans sidebar widget allows the user to display their public loans from Kiva.or on their blog. The user specifies their Kiva lender name, the number of loans (N) to show, and the size of the images that will be displayed. The widget then randomly selects N of the user’s loans from the Kiva API, and displays brief information about each of them. Links to the Kiva.org website
If you have marked any of your Kiva loans as private, or have lent anonymously, your loans will not show up in the Kiva Loans Widget. Only public loans are available to the Kiva.org Loans Widget.
Important: This Kiva Widget requires your Kiva Lender Name. This is not your email that you use to login to Kiva.org! Your Kiva Lender Name is the name Kiva uses in the URL for your Kiva Lender Page. You can access and change your Kiva Lender Name via the last item on “My Lender Page” under “My Portfolio” on Kiva.org.
Installation and Configuration Instructions
1. Download the zip file from accessible from the WordPress Plugins space
2. Upload and unzip into the plugins directory ( /wp-content/plugins/ ) on your server
3. Activate the plugin through the ‘Plugins’ menu in WordPress
3. Add the widget to a sidebar via the ‘Widgets’ page under the ‘Appearance’ menu
4. Set the options, and save your settings
Kiva.org Loans Widget Options
Kiva Lender Name: Your Kiva Lender Name, from “My Lender Page URL” on Kiva
Number of loans: The number you Kiva loans you would like to be displayed
Image Size: The maximum width, or height (which ever is larger) of the image in pixels
FAQ
What is Kiva.org?
A micro-lending site. http://kiva.org
Will it show private loans?
No, it will only show your public Kiva loans.
How do I change the look of the Kiva Loans Widget?
The style sheet is in the plugin folder at /wp-content/plugins/kiva-widget/style.css
What if I get the json_decode error?
Fatal error: Call to undefined function: json_decode() in wp-content/plugins/kivaorg-widget/kiva.php
This error means that you do not have PHP JSON’s support installed on your server. JSON support became a part of the PHP core in PHP 5.2.0. The best way to handle this error is to upgrade your PHP to the newest stable available version. Most Linux distributions will have packages for upgrading. On Windows, you can go to the PHP Downloads page. For more information, check out the PHP JSON Manual.
What if I get the Permission Denied error
Warning: fopen( wp-content/plugins/kivaorg-widget/cache/kiva_cache_1241553368.txt) [function.fopen]: failed to open stream: Permission denied
This error means that improper permissions are set within the Kiva widget directory on your server. The directory ‘cache’ within the widget must be writable by your server’s web users. You can fix this problem by changing the ownership of the directory ‘cache’ to the web user. Most likely one of the following command will work, if performed within the plugin directory ( wp-content/plugins ):
chown www-data:www-data kivaorg-widget/cache
or
chmod 777 /kivaord-widget/cache
Screenshots

The widget displayed on the side bar

The widget's admin control
I hope you enjoy the widget, and love Kiva as much as I do! Please do not hesitate to send questions and comments via the comments of this post. Happy micro-lending!













Marilyn,
Question. I installed the Kiva widget for WordPress, but it doesn’t work. It says that I don’t have any Kiva loans. Au contraire! What I think is missing in your code is the Kiva user password. I put in my username, but without the password, it doesn’t open my account. Can you fix this and post the new widget? I really love Kiva and want to show them at my blog: http://www.chrysalispublications.com/wordpress
Many thanks – in advance.
Carol Plotnick
Hi Marilyn,
Just installed your Kiva plugin. I got this failure in the side:
Warning: array_fill() [function.array-fill]: Number of elements must be positive in /customers/margrieten.nl/margrieten.nl/httpd.www/wp-content/plugins/kivaorg-widget/kiva.php on line 79
When I put in somebody else number, there is nothing wrong, but when I put my username in, it goes wrong!
Is it because I just lend?
Hi Marylin,
I’m having the same problem as Carol. On my website the widget is saying I have not made any loans. I’ve made 17 to date. Can you tell me how I can change this? I would like to display this widget but I look like an idiot for soliciting for Kiva but looking like I haven’t supported them myself.
Thanks,
Alice
http://savorysweetlife.com
Hi Alice.
What are you using for your Kiva Lender Name in the widget? This is a point of confusion with the Kiva system. The widget is expecting the value entered in “My Lender Page URL” under “My Lender Page”, not your email address. If you log into Kiva, then go to: https://www.kiva.org/app.php?page=account&action=lenderPageEdit, you can view and edit this value.
If this doesn’t solve your problem, please let me know, I’ll be happy to investigate further.
Marilyn
With all due respect, most of us don’t have our own server which we can upgrade and my otherwise terrific host (no need to advise switching because I won’t) won’t install that JSON thingy. Alas, no Kiva on my blog…
Afke, I’m sorry that your host has not kept it’s PHP distribution up to date. PHP’s JSON support came out in 2006. I’d be wary of a host that is that out of date!
Is there a way to use a lending team’s account rather than a single user’s? The team URL uses /team/username rather than /lender/username.
Hi Kara,
This is possible, but I’ll have to program it into the widget. It’s a good idea, so I figure I likely will make some time to program it in. I’ll drop you a line when I’ve had the chance to do so. Thanks for the suggestion!
I would also love a team widget if you do come up with one.
Nice widget, I’ll try to install it.
Hi Marilyn! This widget was a great idea — thanks for your efforts in putting it together. Unfortunately, the images don’t seem to be loading my blog (link provided along with my commenter details) — any advice?
Hi jL! From looking at your blog, I’m not sure what exactly is going on. I suspect it’s a permissions issue. Do you have ftp/ssh access to your server? If so, please check that the plugin’s cache directory is writable. (uncarved.prometheas.com/wp-content/plugins/kivaorg-widget/cache/) Are there any images in that directory? If not, then this is the problem. You can fix this by changing the permissions on the cache directory from the root of your wordpress:
chmod 777 wp-content/plugins/kivaorg-widget/cache/
If this doesn’t work for you, please let me know, I’ll be happy to try to help further!
Hey girl!
So I fixed the issue. Perms were fine, but I added a declaration of CURLOPT_RETURNTRANSFER with a value of true in the build_html() function:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$image = curl_exec ($ch);
Every works fine now! Wonder why this bit my ass and no-one else’s tho…… ah, Diversity, you old dog.
Thanks JL!!
I’ve incorporated your change into the widget. The updated version, 2.1, should be available on the WordPress site in a few minutes
http://wordpress.org/extend/plugins/kivaorg-widget/
Hi Marilyn,
I receive this error when running the widget. Any insights on what I can modify to get it to work?
Warning: fopen(/home/ispithot/public_html/Wordpress/wp-content/plugins/kivaorg-widget/cache/kiva_cache_1246947616.txt) [function.fopen]: failed to open stream: No such file or directory in /home/ispithot/public_html/Wordpress/wp-content/plugins/kivaorg-widget/kiva.php on line 193
can't open file: /home/ispithot/public_html/Wordpress/wp-content/plugins/kivaorg-widget/cache/kiva_cache_1246947616.txt
Thanks!
Thanks for the plugin Marilyn- actually should I call you Urpi?
Either Marilyn or Urpi works for me
Marilyn,
I am using WordPress 2.8.1 and your widget is not showing my loans. I am using the correct Kiva name (from the lender page not my email address) and my PHP is up to date. When I installed the widget there was a warning that your widget had not been tested with this version. When I place the widget in my sidebar it says I have no loans. Is this a version conflict and if so will you fix it?
Hi Shannon.
I just released a newer version of the Kiva plugin that works on 2.8.1 for me. Install the new plugin from within the wordpress interface, and it should be installed properly.
If you continue to have problems, please contact me again with more details, including the blog address where the plugin is not working, and your Kiva lender name. Feel free to email me at marilyn[at]urpisdream[dot]com if you do not want to publish that information.
Everything works with the new update. Thanks.
great plugin..
im having a little plugin.. not all my loans are showing.. its showing 15 out of the 30 that i did.. i already set it to show 150.. thnx in advance..
where did you get urpi?
Pretty cool post. I just stumbled upon your blog and wanted to say
that I have really liked reading your blog posts. Anyway
I’ll be subscribing to your blog and I hope you post again soon!
Thank your site for your helping hand.
As they discuss these matters, they can come to appreciate the different dimensions of a problem. ,
Truthful words, some true words dude. Made my day!