How to customize 'read more'

时间:2015-05-30 作者:David Freimaucher

我正在尝试为每个帖子摘录添加一个按钮。但我得到的按钮没有href:

function new_excerpt_more( $more ) {                    
    global $post;
    return "<p><a href=\'" .get_permalink( $post->ID ) ."\' class=\'btn\' >Read more</a></p>";
}
add_filter(\'excerpt_more\', \'new_excerpt_more\');
只有在内容中使用shortcode命令显示摘录时,才会出现问题:

function show_last_articles() {
    $args = array( \'posts_per_page\' => 3, \'category_name\' => \'xyz\');
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ):
        setup_postdata( $post );
            $return = "<div class=\'excerpts\'>";
            $return .= "<h2><a href=\'" .get_the_permalink( $post->ID ) ."\'>" .get_the_title( $post->ID ) ."</a></h2>";
            $return .= "<div>" .get_the_excerpt( $post->ID ) ."</div>";
            $return .= "</div>";
    endforeach; 
    wp_reset_postdata();
    return $return;
}
add_shortcode( \'last_articles\', \'show_last_articles\');
怎么了?

1 个回复
SO网友:Brad Dalton

这只会使“阅读更多”链接成为一个按钮。

add_filter( \'excerpt_more\', \'wpsites_read_more_link\' );
    function wpsites_read_more_link( $more ) {
        return \'... <a class="more-link button" href="\' . get_permalink() . \'">Continue Reading</a>\';
}
用主题按钮类替换按钮类。

结束

相关推荐