get_extended()
最后更新于:2021-11-26 09:08:53
get_extended( string$post)Get extended entry info (<!--more-->
).
参数
- $post
-
(string) (Required) Post content.
响应
(string[]) Extended entry info.
-
‘main’
(string) Content before the more tag. -
‘extended’
(string) Content after the more tag. -
‘more_text’
(string) Custom read more text, or empty string.
源文件
文件: gc-includes/post.php
function get_extended( $post ) {
// Match the new style more links.
if ( preg_match( '/<!--more(.*?)?-->/', $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,
);
}
<ul> $post = get_post(); $myposts = get_posts( array( 'posts_per_page' => 5 ) ); foreach( $myposts as $post ) : setup_postdata( $post ); $content_arr = get_extended ( $post->post_content ); ?> <li> <a href="https://docs.gechiui.com/functions/get_extended/<?php the_permalink(); ?>"><?php the_title(); ?></a> </br> <?php echo $content_arr['main']; // Display the part before the more tag ?> </li> <?php endforeach; ?> </ul>