描述:
获取扩展信息
用法:
<?php get_extended( $post_content ) ?>
参数:
$post_content
(string) (必填) 文章内容
默认值: None
示例:
显示最新帖子的小摘录。
如果你想在你的WordPress博客上显示最新的文章,但是只显示<!--更多-->标记,您可以使用:
<ul>
<?php
global $post;
$args = array( 'numberposts' => 5 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata( $post );
$content_arr = get_extended (get_the_content() ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</br>
<?php echo $content_arr['main']; //Display the part before the more tag ?>
</li>
<?php endforeach; ?>
</ul>
源文件:
/**
* Get extended entry info ().
*
* There should not be any space after the second dash and before the word
* 'more'. There can be text or space(s) after the word 'more', but won't be
* referenced.
*
* The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before
* the ``. The 'extended' key has the content after the
* `` comment. The 'more_text' key has the custom "Read More" text.
*
* @since 1.0.0
*
* @param string $post Post content.
* @return array Post before ('main'), after ('extended'), and custom readmore ('more_text').
*/
function get_extended( $post ) {
//Match the new style more links.
if ( preg_match('//', $post, $matches) ) {
list($main, $extended) = explode($matches[0], $post, 2);
$more_text = $matches[1];
} else {
$main = $post;
$extended = '';
$more_text = '';
}
// leading and trailing whitespace.
$main = preg_replace('/^[s]*(.*)[s]*$/', '\1', $main);
$extended = preg_replace('/^[s]*(.*)[s]*$/', '\1', $extended);
$more_text = preg_replace('/^[s]*(.*)[s]*$/', '\1', $more_text);
return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text );
}