我想知道如何做到以下几点:
我想在45个单词之后做一个摘录,但如果帖子的文本少于45个单词,并且帖子中包含图像,那么应该在文本后面包含更多的标签。
第一:我会对这个解决方案感到满意。2:在这种情况下,最好有一个可供选择的句子。“单击以查看图片。”
希望这篇文章对任何阅读本文的人都有意义。
目前我有以下内容:
/*-----------------------------------------------------------------------------------*/
/* Sets the post excerpt length to 15 characters.
/*-----------------------------------------------------------------------------------*/
function moka_excerpt_length( $length ) {
return 45;
}
add_filter( 'excerpt_length', 'moka_excerpt_length' );
/*-----------------------------------------------------------------------------------*/
/* Returns a "Continue Reading" link for excerpts
/*-----------------------------------------------------------------------------------*/
function moka_excerpt_more( $more ) {
return '… <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __( 'Read more', 'moka' ) . '</a>';
}
add_filter( 'excerpt_more', 'moka_excerpt_more' );任何帮助都是非常感谢的。
非常感谢和亲切的问候。
发布于 2014-09-01 03:27:31
我想,你可以自己写代码。你可以给the_content()添加滤镜,或者用另一种方法:参考这个:http://wordpress.org/support/topic/executing-a-function-only-if-a-post-contains-an-image,你可以检查the_content()是否有img?!对于计算the_content()中的单词,这个答案很有用:Counting words on a html web page using php
发布于 2014-09-03 06:12:11
我做了一些更深入的研究,得出了以下结论。我知道它不会工作,但有些部分是独立工作的,但是我不能把所有的东西都放在一起。也许有人能帮我指出正确的方向?
function individual_excerpt_more( $more ) {
if {
function word_count() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
return $word_count; <45 // (less than 45 words)
}
&& $content = $post->post_content;
if( has_shortcode( $content, 'gallery', 'video' ) ) {
// The content has a [gallery] & [video] short code, so this check returned true.
}
return '… <ins><a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read more</a></ins>';
}
else {
function theme_excerpt_length( $length ) {
return 45;
}
add_filter( 'excerpt_length', ’theme_excerpt_length' );
}
add_filter( 'excerpt_more', 'individual_excerpt_more' );https://stackoverflow.com/questions/25594868
复制相似问题