Pinterest wallpaper

Pinterest is the number one social media network for sharing images, hands down. Ever since it made its appearance on the web, it has quickly (and swiftly) made its way into the top ten social networks to be a part of, even if data claims that majority of the audience are females.

In very recent news, Pinterest has announced that it is rolling out its Promoted Pins platform (which was in testing stages for over a year) to the public, you can follow-up on that story either on their official blog, or on this Gigaom article.

There is a lot to be gained from being a member on Pinterest, and not just inspirational images or quotes. It’s a never-ending stream of news, products to explore, and beautiful stories crafted by its unique community. In this post, we’re going to take a look at some webmaster/developer related snippets that we can use to our advantage to make the most out of Pinterest.

Fetch Latest Pins from Users Board with PHP

Just fill in the right values for $pin_id and $board and save the file as .php and you’re good to go. If you can’t find any good use for it, at least you get to see how such an action would work in the real-world.

< ?php //Pinterest Feed function fetchPinterest($url){ $result = file_get_contents($url); $x = simplexml_load_string($result); return $x; } $pin_id = "profile-id"; $board = "board-name"; $pin_feed = "http://pinterest.com/" . $pin_id . "/" . $board . "/rss"; $result_pin = fetchPinterest($pin_feed); $pin_count = 0; foreach($result_pin->channel->item as $item) {
	if($pin_count == 0) {
		$item_description = $item->description;
		$regex = "/])*)>/";
		preg_match($regex, $item_description, $matches);
		echo $matches[0];
	}
	$pin_count++;
}

?>

// Credit: qnacreative

Block Pinterest From Pinning Your Images

Are you displeased with the traffic that you’re recieiving from Pinterest, or simply want to avoid it all together? Here is a nice function that you can use on your WordPress blog to block Pinterest from sharing your images, the other solution is to copy/paste the HTML code in your non-WordPress site for the same effect.

function no_images_pinning() {
    echo '';
}
add_action( 'wp_head', 'no_images_pinning' );
// Credit: brandonhimpfen

Latest Pinterest Pins in JSON Format

If you’re building Pinterest related projects using PHP, this snippet can be a good starting point to export the latest – global – Pinterest pins in JSON format.

< ?php class XmlToJson { public function Parse( $url ) { $fileContents = file_get_contents( $url ); $fileContents = str_replace( array( "\n", "\r", "\t" ), '', $fileContents ); $fileContents = trim( str_replace( '"', "'", $fileContents ) ); $simpleXml = simplexml_load_string( $fileContents ); $json = json_encode( $simpleXml ); return $json; } } function msh_pinterest() { $xml = new XmlToJson; $feed = json_decode( $xml->Parse( "http://pinterest.com/pinterest/feed.rss" ) );
  $items = $feed->channel->item;

  foreach( $items as $item ) :
    printf( '%s', $item->description );
  endforeach;
}
// Credit: moimikey

Pinterst Likes Counter in JavaScript

The following function can be used to integrate within PHP scripts, or simply used as a way of grabbing the total amount of Pinterest shares for any particular URL/Image.

function getPinterestCount(url, countElement) {
    var pinterestUrl = "http://api.pinterest.com/v1/urls/count.json?callback=?&url=" + url;
    $.getJSON(pinterestUrl, function (data) {
        $(countElement).text(data.count);
    });
}
// Credit: marcusgadbem

“Pin It” Button Hover Effect Over Images

This following snippet utilizes the “pinit.js” library that’s built by the Pinterest team itself. There are quite a few ways to approach this particular issue, but this is one of the safest ways to do it. To make it work you have to add it before your closing HEAD tag of your site.


Conclusion: –
It’s evident that there is huge demand for this kind of stuff, especially when you browse public library and plugin directories. Why waste your servers memory by installing 3rd-party plugins when you can just use simple solutions such as the ones we’ve taken a look at in this post? Either way, it’s also a great practice to better understand how such concepts work, and how to integrate them within your own projects.

I’d love to see more of your own snippets, and I’d be more than happy to add them to this post on your behalf and give you the appropriate credit. Let me know, and share your thoughts on the ones we’ve already got.