Here are some of common functions in WordPress theme’s functions.php file that I would suggest you include in your functions.php file
Get Ping/Trackback Count
Here is an interesting one I used recently. This function returns the number of pings/trackbacks for a post. This can be useful if you only want to show a certain section if there are any pings/trackbacks.
Plain Text Feedburner Subscriber Count
Here is the classic: get your feedburner subscriber count in plain text. Note most of these functions make use of cURL and this one requires PHP v5+ (so you can use SimpleXMLElement).
Get TinyURL
This one can be useful if you want to generate a short URL of your post for people to share.
Get Ping/Trackback Count
Here is an interesting one I used recently. This function returns the number of pings/trackbacks for a post. This can be useful if you only want to show a certain section if there are any pings/trackbacks.
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ function pings_count($post_id) { global $wpdb; $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE (comment_type = 'pingback' OR comment_type = 'trackback') AND comment_post_ID = '$post_id'"; return $wpdb->get_var($count); } ?>
Plain Text Feedburner Subscriber Count
Here is the classic: get your feedburner subscriber count in plain text. Note most of these functions make use of cURL and this one requires PHP v5+ (so you can use SimpleXMLElement).
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ function get_subscriber_count() { $id = "YourFeedId"; $url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=". $id; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($data); return $xml->feed->entry['circulation']; } ?>
Get TinyURL
This one can be useful if you want to generate a short URL of your post for people to share.
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ function get_tiny_url($url) { if (function_exists('curl_init')) { $url = 'http://tinyurl.com/api-create.php?url=' . $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $tinyurl = curl_exec($ch); curl_close($ch); return $tinyurl; } else { //cURL disabled on server; Return long URL instead. return $url; } } ?>
0 comments:
Post a Comment