<div id="posts">
<?php
// define query arguments
$args = array(
\'posts_per_page\' => 8, // your \'x\' goes here
\'nopaging\' = true
// possibly more arguments here
);
// set up new query
$tyler_query = new WP_Query( $args );
// loop through found posts
while ( $tyler_query->have_posts() ) : $tyler_query->the_post();
echo \'<section class="post">\'.
\'<h2><a href="\'.
get_permalink().
\'">\'.
get_the_title().
\'</a></h2><p>\'.
get_the_excerpt().
\'</p></section>\';
endwhile;
// reset post data
wp_reset_postdata();
?>
</div>
默认情况下,摘录长度为55个单词。对于自定义摘录长度,请在主题的
函数中删除以下内容。php:function tyler_excerpt_length( $length ) {
return 70; // change number of words to your liking
}
add_filter( \'excerpt_length\', \'tyler_excerpt_length\' );
如果您对摘录末尾的默认“继续阅读”链接不满意,请将其放入函数中。php:function tyler_excerpt_more( $more ) {
return \'Read the whole post >>\'; // again, change to your liking
}
add_filter( \'excerpt_more\', \'tyler_excerpt_more\' );
如果由于标题中有post链接,因此希望不显示摘录的“more”链接,请让上面的函数返回一个空字符串,即。return \'\';
.进一步阅读: