I lifted the "continue reading" link functions from the Twenty Eleven theme and for the most part, it is working (works in RSS feeds).
I created a shortcode to display the latest post on the front static page using get_posts
, however, the "continue reading" link just links to the front page instead of the post page.
function gavsiu_continue_reading_link() {
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Read more <span class="meta-nav">»</span>' ) . '</a>';
}
function gavsiu_auto_excerpt_more( $more ) {
return ' …' . gavsiu_continue_reading_link();
}
add_filter( 'excerpt_more', 'gavsiu_auto_excerpt_more' );
function gavsiu_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= gavsiu_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'gavsiu_custom_excerpt_more' );
Shortcode:
function gavsiu_recent_posts( $atts ) {
extract( shortcode_atts( array(
'cat' => 3,
'max_posts' => 1
), $atts ) );
$recent_posts = get_posts( array(
'category' => "{$cat}",
'numberposts' => "{$max_posts}"
) );
foreach($recent_posts as $recent_post) : setup_postdata($recent_post);
$post = '<h4 class="recent-post-title c0">' . $recent_post->post_title . '</h4>';
$post .= '<p class="recent-content c0">' . get_the_excerpt() . '</p>';
return $post;
endforeach;
}
add_shortcode( 'recent_posts', 'gavsiu_recent_posts' );