如果可用,我计划显示帖子摘录而不是内容,如果不可用,则使用以下功能自动生成内容摘录:
<?php the_content( __( \'Continue reading <span class="meta-nav">→</span>\', \'blabla\' ) ); ?>
在中
functions.php
我补充说:
# Function to trim the excerpt
if (!function_exists(\'narga_excerpts\')) :
function narga_excerpts($content = false) {
# If is the home page, an archive, or search results
global $post;
$excerpt_length = 40;
# If an excerpt is set in the Optional Excerpt box
if ( $post->post_excerpt ) {
$content = the_excerpt();
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( \'excerpt_length\', \'custom_excerpt_length\', 999 );
function excerpt_readmore($more) {
return \'... <a title="\' . the_title_attribute(\'echo=0\') . \'" href="\'. get_permalink($post->ID) . \'" class="more-link"> \' . __( \'Read more »\', \'narga\' ) . \' </a>\';
}
add_filter(\'excerpt_more\', \'excerpt_readmore\');
}
# If no excerpt is set
else {
$content = $post->post_content;
$words = explode(\' \', $content, $excerpt_length + 1);
if(count($words) > $excerpt_length) {
array_pop($words);
$content = implode(\' \', $words);
}
}
$content = \'<p>\' . $content . \'</p>\';
# Make sure to return the content
return $content;
}
# Replace content with excerpt
add_filter(\'the_content\', \'narga_excerpts\');
endif;
但它不起作用。