更改wordpress帖子中的文本

时间:2014-01-12 16:33:51

标签: php wordpress

我正在使用这个PHP在外部网站上显示Wordpress博客文章:

<?php
$posts = get_posts('numberposts=10&order=DESC&orderby=post_date');
    foreach ($posts as $post) {
        setup_postdata( $post );
        ?><h2><a href="/blog/<?php echo $post->post_name; ?>"><?php the_title(); ?></a></h2><br>
        Posted on <?php the_date(); ?><br><br>
        <?php the_excerpt(); ?>
        <br><hr /><br>
        <?php
    }
?>

如何将摘录末尾的[...]更改为[Read More]

1 个答案:

答案 0 :(得分:1)

将此代码复制到主题的functions.php文件中:

function new_excerpt_more( $more ) {
    return '[Read more]';
}
add_filter('excerpt_more', 'new_excerpt_more');

或者,如果您想在文本上添加帖子的链接:

function new_excerpt_more( $more ) {
    return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More</a>';
 }
 add_filter( 'excerpt_more', 'new_excerpt_more' );
相关问题