I’ve been working with the Facebook Comment integration into WordPress lately. Mostly because it can help cut down on spam, but also because of the grammer checker and social media benefit. I couldn’t really find a good solution online for pulling the number of comments on any given post, so here is what I ended up with. I included this in my functions.php file, and just put this: <?php get_fb_comment_count(); ?> in my single.php file where I want the comment number to be displayed.
function get_fb_comment_count() {
global $post;
$url = get_permalink($post->ID);
$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
$json = json_decode($filecontent);
$count = $json->$url->comments;
if ($count == 0 || !isset($count)) {
$count = 'No Comments';
} elseif ( $count == 1 ) {
$count = '1 Comment';
} else {
$count .= ' Comments';
}
echo $count;
}
I often run into situations where I am editing a site, or checking my pages, but do not want to count the time i spend on my own site to count towards my Analytics Tracking.
Read more
Written by Mike PaynePosted in Blog,Development,Snippet,WordpressTags: Development, hack, PHP, publish, Snippets, user roles, WordPressSeptember 29, 2011
A common issue many beginner WordPress users run into is blocking certain content from users that aren’t registered or logged in. Here is a short, simple solution in the form of a shortcode.
Read more
I had the great opportunity to speak at this years WordCamp SLC over the weekend. If you haven’t been to a WordCamp, it is a conference where a bunch of WordPress experts get together and share their knowledge and experiences with the open source platform. If you have been to a WordCamp, then it is the same thing
Read more
Written by Mike PaynePosted in Blog,Development,Snippet,WordpressTags: cmd+s, ctrl+s, Development, hack, javascript, jquery, page, PHP, post, publish, shortkey, Snippets, WordPressAugust 16, 2011
I spend a lot of time coding. a lot. So much so, that when I write posts and pages on my WordPress sites and go to save it, I hit Ctrl+S (Cmd+S on Mac), which is the short-key to save in pretty much any program ever made. It can get frustrating to save and have to stop, exit out of the popup window trying to save the website locally, and then hit the Update button. So, this snippet covers how to detect when a page is loaded, output scripts, see when a user presses multiple buttons across operating systems, stop the default reaction from the browser, and finally activate a button.
Read more