ryarwood
3/18/2013 - 9:26 PM

Load first post outside wordpress.

Load first post outside wordpress.

<?php
include(str_replace('//','/',dirname(__FILE__).'/') .'../news/wp-load.php');
$postslist = get_posts('numberposts=1');
foreach ($postslist as $post) :
setup_postdata($post);
?>

<h2><?php the_time('F j, Y'); ?></h2>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>

<?php endforeach; ?>
<?php
/**
* @package WordPress
* @subpackage p11news
*/

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_trim_excerpt');

function custom_trim_excerpt($text) { // Fakes an excerpt if needed
  global $post;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]>', ']]>', $text);
		$text = strip_tags($text);
		$excerpt_length = 18;
		$words = explode(' ', $text, $excerpt_length + 1);
		if (count($words) > $excerpt_length) {
			array_pop($words);
			array_push($words, '... <a href="/news/" class="more">More &gt;</a>');
			$text = implode(' ', $words);
		}
	}
	$text = str_replace(' ...', '...', $text);
	return $text;
}

?>