我正在尝试为每个帖子摘录添加一个按钮。但我得到的按钮没有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\');
怎么了?