How To Render Your Twitter Followers Count In Your WordPress Blog
Adding the following snippet to your theme’s functions.php file, you will be able to render your Twitter followers count. Also, remember to replace “planetabhi” with your own Twitter screen name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
function my_followers_count($screen_name = 'planetabhi'){ $key = 'my_followers_count_' . $screen_name; // Let's see if we have a cached version $followers_count = get_transient($key); if ($followers_count !== false) return $followers_count; else { // If there's no cached version we ask Twitter $response = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name={$screen_name}"); if (is_wp_error($response)) { // In case Twitter is down we return the last successful count return get_option($key); } else { // If everything's okay, parse the body and json_decode it $json = json_decode(wp_remote_retrieve_body($response)); $count = $json->followers_count; // Store the result in a transient, expires after 1 day // Also store it as the last successful using update_option set_transient($key, $count, 60*60*24); update_option($key, $count); return $count; } } } echo "I have " . my_followers_count('planetabhi') . " followers"; |
Snippet Source/Credit: Snipplr
How To Use Gravatars In Your Script
The following snippet will let you use gravatars in your script.
1 2 3 4 5 6 7 8 |
<?php function show_my_gravatar($email, $size, $default, $rating) { $params = '?gravatar_id='.md5($email).'&default='.$default.'&size='.$size.'&rating='.$rating; $output = '<img src="http://www.gravatar.com/avatar.php'.$params.'" width="'.$size.'px" height="'.$size.'px" />'; echo $output; } ?> |
Snippet Source/Credit: AppHP
How To Generate Your Own Portfolio With Filtering Based On Taxonomy
Using the following snippet will let you generate your own portfolio with the help of filtering based on taxonomy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
<?php // get portfolio $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'asc' ); $loop = new WP_Query( $args ); $port = array(); while ( $loop->have_posts() ) : $loop->the_post(); $idx = get_the_ID(); $year_completed = get_post_meta($idx, 'year_completed', true); $website_addr = get_post_meta($idx, 'website_address', true); $thumb = get_the_post_thumbnail($idx, 'thumbnail'); //250x200 - featured image $title = get_the_title(); $excerpt = get_the_excerpt(); $content = get_the_content(); //get 'Solutions' terms $terms = get_the_terms($idx, 'Solutions'); $terms_string = ''; //build up comma delimited string foreach($terms as $t){ $terms_string .= $t->slug . ' '; } $port[] = array( 'id' => $idx, 'year_completed' => $year_completed, 'website' => $website_addr, 'thumb' => $thumb, 'title' => $title, 'content' => $content, 'excerpt' => $excerpt, 'terms' => $terms, 'terms_string' =>$terms_string, //classifications (comma delimited slugs) 'permalink' => get_permalink(), ); endwhile; $terms = get_terms('Solutions'); $filters = '<section id="options" class="clearfix"> <ul id="filters" class="option-set floated clearfix"> <li><a href="#filter" data-filter="*" class="selected">show all</a></li>'; foreach($terms as $t){ $filters .= '<li><a href="#filter" data-filter=".' . $t->slug . '">' . $t->name . '</a></li>';// $t->count } $filters .= '</ul></section>'; ?> <!-- add this inside entry-content --> <?php echo $filters; ?> <div id="portfolio"> <!-- isotope --> <ul class="thumbnails isotope"> <?php foreach($port as $p){ ?> <li class="span3 element <?php echo $p['terms_string']; ?>"> <div class="thumbnail"> <?php echo $p['thumb']; ?> <div class="caption"> <h5><a href="<?php echo $p['permalink']; ?>"><?php echo $p['title']; ?></a></h5> </div><!-- end caption --> </div><!-- end thumbnail --> </li> <? } //end foreach ?> </ul> </div><!-- end #portfolio --> |
Snippet Source/Credit: ToddWilson
How To Get Template For WordPress Widget
Using the following snippet will let you get template for WordPress widget.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* Plugin Name: Your Plugin Name Here Plugin URI: http://yourpluginsite.com Description: This displays your Blogs in your WP Network Author: The Author Name Here Version: 1.0.0 Author URI: http://theauthoraddress.com */ class My_Widget extends WP_Widget { public function __construct() { // widget actual processes } public function form( $instance ) { // outputs the options form on admin } public function update( $new_instance, $old_instance ) { // processes widget options to be saved } public function widget( $args, $instance ) { // outputs the content of the widget } } add_action( 'widgets_init', create_function( '', 'register_widget( "My_Widget" );' |
Snippet Source/Credit: Snipplr