Cached Twitter Follower Count
The following WordPress snippets will cached Twitter follower count
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function get_follower_Count(){ $count = get_transient('follower_count'); if ($count !== false) return $count; $count = 0; $data = wp_remote_get('http://api.twitter.com/1/users/show.json?screen_name=YOURNAME'); if (!is_wp_error($data)) { $value = json_decode($data['body'],true); $count = $value['followers_count']; } set_transient('follower_count', $count, 60*60); // 1 hour cache return $count; } |
Add the first section of code to the functions.php of your WordPress theme. This code will cache your Twitter follower number for 1 hour and display the count within your template.
1 2 3 4 5 |
<? get_follower_count(); ?> |
Source: Snipplr
Share wp-articles on Twitter
The following snippet will share wp-articles on Twitter
1 2 3 |
<?php $excerpt = strip_tags(get_the_excerpt()); ?> <a href="http://twitter.com/home?status=<?php the_title(); ?><?php echo $excerpt; ?>" rel="nofollow" title="retweet on twitter">Share on Twitter</a> |
Remove Personal Options from Profile Menu
The following snippet will allow you to remove personal options from personal menu
1 2 3 4 5 6 7 |
function hide_personal_options(){ echo "\n" . '<script type="text/javascript">jQuery(document).ready(function($) { $(\'form#your-profile > h3:first\').hide(); $(\'form#your-profile > table:first\').hide(); $(\'form#your-profile\').show(); });</script>' . "\n"; } add_action('admin_head','hide_personal_options'); |
Source: Snipplr
Get Posts By Term and Sort Them
The following snippet will get posts by term and even sort them
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 69 70 71 72 73 74 75 |
<?php $args = array( 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ); $posts = array(); foreach( get_posts($args) as $post ): $terms = array(); foreach(wp_get_object_terms( $post->ID, array('taxonomy1', 'taxonomy2') ) as $term) { //Works if there is only one term tagged in the post for this taxonomy. You need to figure out how best to handle multiple terms. You might try imploding() them in a comma seperated list: "Term 1, Term 2" $post[$term->taxonomy] = $term->name; } $posts[] = (object) $post; endforeach; /** * Sort array of objects by field. * * @param array $objects Array of objects to sort. * @param string $on Name of field. * @param string $order (ASC|DESC) **/ function sort_on_field(&$objects, $on, $order = 'ASC') { $comparer = ($order === 'DESC') ? "return -strcasecmp(\$a->{$on},\$b->{$on});" : "return strcasecmp(\$a->{$on},\$b->{$on});"; usort($objects, create_function('$a,$b', $comparer)); } /* Use `strcmp` for case-sensitive string comparing. Use `strcasecmp` for case-insensitive string comparing. Source: http://www.php.net/manual/de/function.usort.php#104873 */ sort_on_field($posts, 'taxonomy1', 'DESC'); foreach( $posts as $post ) { echo $post->taxonomy1; } ?> |
Source: Snipplr
Remove or Hide Admin Menu Links for Certain or Specific Users or Roles
The following snippet will let you remove as well as hide admin menu links for certain users or role.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
if (current_user_can('hide_jobs')) { add_action( 'admin_menu', 'my_remove_menu_jobs' ); function my_remove_menu_jobs() { remove_menu_page('edit.php?post_type=job'); remove_menu_page('edit.php?post_type=solution'); remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); // right now } } |
Source: Snipplr
Add featured image thumbnail to admin columns
The following snippet will add featured image thumbnail to admin columns
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 |
// Add the posts and pages columns filter. They can both use the same function. add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5); add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5); // Add the column function tcb_add_post_thumbnail_column($cols){ $cols['tcb_post_thumb'] = __('Featured'); return $cols; } // Hook into the posts an pages column managing. Sharing function callback again. add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2); add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2); // Grab featured-thumbnail size post thumbnail and display it. function tcb_display_post_thumbnail_column($col, $id){ switch($col){ case 'tcb_post_thumb': if( function_exists('the_post_thumbnail') ) echo the_post_thumbnail( 'admin-list-thumb' ); else echo 'Not supported in theme'; break; } } |
Source: TCBarrett.com