Last active
December 15, 2015 02:59
-
-
Save ryarwood/5190968 to your computer and use it in GitHub Desktop.
Load first post outside wordpress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ></a>'); | |
$text = implode(' ', $words); | |
} | |
} | |
$text = str_replace(' ...', '...', $text); | |
return $text; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment