Display number of Facebook fans in full text

Display number of Facebook fans in full text

Display number of Facebook fans in full text

If you have a Facebook page for your website or blog, you might want to display how many fans you have. This snippet will help you to get your Facebook fan count, in full text. Don’t forget to add your page ID on line 2. Your page ID can be found at the address http://facebook.com/yourpagename/info.

<?php
 $page_id = "302807633129400";
 $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
 $fans = $xml->page->fan_count;
 echo $fans;
?>
How to Promote your RSS feed on every post

How to Promote your RSS feed on every post

How to Promote your RSS feed on every post

Adding this snippet to the functions.php of your wordpress theme will add a link to your rss feed at the bottom of every post. If you are looking to get some new subscribers this is a great way to promote your feed.

WORDPRESS SNIPPET : PHP

function wps_promote_feed($content,$class = "promote") {
    echo $content;
    if (is_single()) {
?>
        <div class="<?php echo $class; ?>">
            <h3>Enjoyed this article?</h3>
            <p>Please consider subscribing to our <a class="feed" href="<?php bloginfo('rss2_url'); ?>" title="Subscribe via RSS">RSS feed!</a></p>
        </div>
<?php
    }
}
add_filter('the_content','wps_promote_feed');

( WordPress codex functions, hooks, in this snippet. )

the_content, bloginfo, is_single, add_filter, wp,

How to Track post views without a plugin using post meta

How to Track post views without a plugin using post meta

How to Track post views without a plugin using post meta

Use the following snippet to track post views on your wordpress blog. The first thing you want to do is add this snippet to the functions.php of your wordpress theme. Follow step 1. and step 2. to track and display the number of views for each post. Updated this snippet from my original post on March 3rd, 2011 to Included a option for Fragment Caching so this snippet will work even on cached pages.

 

WORDPRESS SNIPPET : PHP – FUNCTIONS.PHP

function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

Step 1.

This part of the tracking views snippet will set the post views. Just place this snippet below within the single.php inside the wordpress loop.

 

WORDPRESS SNIPPET : PHP – SINGLE.PHP

<>
<?php
          setPostViews(get_the_ID());
?>

Fragment Caching

Note: If you are using a caching plugin like W3 Total Cache, the method above to set views will not work as the setPostViews()function would never run. However W3 Total Cache has a feature called fragment caching. Instead of the above use the following so the setPostViews() will run just fine. Tracking all your post views even when you have caching enabled.

 

WORDPRESS SNIPPET : PHP – SINGLE.PHP

<!-- mfunc setPostViews(get_the_ID()); --><!-- /mfunc -->

Step 2.

The snippet below is optional, so use this if you would like to display the number of views within your posts. Place this snippet within the loop.

 

WORDPRESS SNIPPET : PHP – SINGLE.PHP / INDEX.PHP

<?php
          echo getPostViews(get_the_ID());
?>

( WordPress codex functions, hooks, in this snippet. )

delete_post, wp_head, get_post, get_the_ID, the_ID, add_post_meta, delete_post_meta, get_post_meta, update_post_meta, remove_action, wp,