The new EricMartindale.com is an experiment in data aggregation, and might have a few bugs. Feel free to explore, and then provide feedback directly to @martindale.

search results for foursquare

Display Foursquare Badges in Chyrp without using Javascript

If you notice, I currently display my Foursquare badges over in the right hand side. I'm not sure about how long I'll display them specifically, so here's a screenshot:

I recently received an email inquiring about how I accomplished this. Well, since I use Chyrp, here's how I did it:

  1. In includes/controller/Main.php, add the following, somewhere around line 715 (immediately after $this->context["sql_queries"] =& SQL::current()->queries;): // BEGIN Foursquare Badges $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, "http://api.foursquare.com/v1/user.json?badges=1"); curl_setopt($cURL, CURLOPT_HEADER, 0); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($cURL, CURLOPT_USERPWD, "your@email.com:your_password_here"); $strPage = curl_exec($cURL); curl_close($cURL); $foursquare = json_decode($strPage); $badges = $foursquare->user->badges; foreach ($badges as $badge) { $this->context['foursquare_badges'] .= '<img src="'.$badge->icon.'" title="'.$badge->description.'" />'; }
    // END Foursquare Badges
  2. In themes/your_theme_name/content/sidebar.twig, wherever you want to display your foursquare tags, simply add: <div> <h1>Foursquare Badges</h1> $foursquare_badges </div></code> You can display this wherever you like, in any part of your Chyrp template.

Be aware that this requires PHP's CURL module. I encourage you to enable Chyrp's caching module as well, so every page load does not incur a single API request (I have a feeling that they probably won't appreciate it). The benefit of this is that your Foursquare badges will now be output by your server, so they are both indexable by search engines and degrade very gracefully when the client doesn't have Javascript enabled (NoScript users, particularly).

Enjoy!

0 Replies

Replies are automatically detected from social media, including Twitter, Facebook, and Google+. To add a comment, include a direct link to this post in your message and it'll show up here within a few minutes.