All pastes #1954936 Raw Edit

Lee H

public text v1 · immutable
#1954936 ·published 2010-10-05 16:09 UTC
rendered paste body
/* THIS SECTION BELONGS IN THE HEADER SECTION */


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" <?php language_attributes(); ?>>

<head>

<?php if (have_posts()):while(have_posts()):the_post();endwhile;endif; //This line needed so content image grabbing is possible ?>



	<meta property="fb:app_id" content="MY-FB-APP-ID-NUMBER" />

	<meta property="fb:admins" content="MY-FB-USER-ID-NUMBER" />

<?php if ( is_home() ) { ?>

		<meta property="og:url" content="http://www.MY-MAINPAGE-URL.com/"/>

	<?php } else { ?>

		<meta property="og:url" content="<?php the_permalink(); //Dynamic URL if not main page ?>"/>

<?php } ?>

<?php if (is_single()) { ?>  <!--Meta if single-->

	<meta property="og:title" content="<?php single_post_title(''); ?>" />

	<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); //Creates description from post excerpt ?>" />

	<meta property="og:type" content="article" />

	<meta property="og:image" content="<?php echo catch_that_image(); //Function grabs first image from post content, make sure functions.php has this. ?>" />

<?php } else { ?>

	<meta property="og:title" content="<?php bloginfo('name'); ?>" />

	<meta property="og:description" content="DESCRIPTION-THAT-WILL-APPEAR-ON-MAIN-PAGE-ONLY" />

	<meta property="og:type" content="website" />

	<meta property="og:image" content="http://www.URL-TO-IMAGE-FOR-MAIN-PAGE/my-fb-image.jpg" />

<?php } ?>

/*END HEADER SECTION*/

/*PASTE THIS FUNCTION IN FUNCTIONS.PHP*/

// Get URL of first image in a post

function catch_that_image() {

	global $post, $posts;

	$first_img = '';

	ob_start();

	ob_end_clean();

	$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

	$first_img = $matches [1] [0];



	// no image found display default image instead

	if(empty($first_img)){

	$first_img = "/images/default.jpg";

	}

	return $first_img;

}

/*THAT'S ALL FOLKS*/