阅读更多标签显示在每个帖子
1 个回答
- 投票数
-
- 2015-10-29
实际上,我从来没有将这一部分添加到您所指的答案中.要从摘录中删除阅读更多链接非常简单,只需将
$count
与$excerpt_length
进行比较即可.$count
始终在0
和分配给$excerpt_length
的值之间.因此,我们要做的是在条件为条件下添加更多阅读链接,该条件指出如果$count
小于$excerpt_length
,我们不应显示更多要将这些内容全部放入代码中,只需替换以下部分
$excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s »', 'wpse' ), get_the_title()) . '</a>'; $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); //$pos = strrpos($wpse_excerpt, '</'); //if ($pos !== false) // Inside last HTML tag //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */ //else // After the content $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */
与
if ( $count >= $excerpt_word_count ) { $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s »', 'wpse' ), get_the_title()) . '</a>'; $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); //$pos = strrpos($wpse_excerpt, '</'); //if ($pos !== false) // Inside last HTML tag //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */ //else // After the content $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */ }
I actually never got to add this section to my answer you are referring to. To remove the read more link from the excerpt is quite easy, you just need to compare
$count
with$excerpt_length
.$count
will always be between0
and the value assigned to$excerpt_length
. So what we want to do here is to add the read more link in a condition that states that if$count
is less than$excerpt_length
, we should not display the read moreTo put that all in code, you simply need to replace the following section
$excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s »', 'wpse' ), get_the_title()) . '</a>'; $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); //$pos = strrpos($wpse_excerpt, '</'); //if ($pos !== false) // Inside last HTML tag //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */ //else // After the content $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */
with
if ( $count >= $excerpt_word_count ) { $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s »', 'wpse' ), get_the_title()) . '</a>'; $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); //$pos = strrpos($wpse_excerpt, '</'); //if ($pos !== false) // Inside last HTML tag //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */ //else // After the content $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */ }
-
传说自己! 很好,Pieter,像个魔咒一样工作,谢谢!The legend himself! That's great, Pieter, working like a charm, thank you!
- 4
- 2015-10-29
- Jeff W
-
我很高兴,很高兴它能起作用;-)My pleasure, glad it worked, enjoy ;-)
- 0
- 2015-10-29
- Pieter Goosen
-
彼得,随着时间的推移,我注意到"阅读更多"按钮不会显示在所有帖子上.我首先在使用loremipsum的虚拟帖子上注意到了它,但是现在我正在处理一个项目,其中有多个帖子无法使用.您是否知道我在做什么错而导致按钮不显示?我在执行所有操作时都使用引导CDN.Pieter, I've noticed over time that the read more button won't display on all posts. I first noticed it on dummy posts using lorem ipsum but I've got a project I'm working on now that has several posts it's not working on. Do you have any idea what I may be doing wrong that makes it so that the button won't display? I'm using bootstrap CDN on everything I do.
- 0
- 2016-03-04
- Jeff W
-
没关系!我想我已经找到了解决方案,将$ count更改为> 0Nevermind! I think I've found a solution by changing the $count to >0
- 0
- 2016-03-04
- Jeff W
我最近阅读了这篇很棒的帖子,我需要帮助弄清楚如何显示"阅读更多"链接仅适用于内容更多的帖子.就目前而言,即使是简短的一句,它也会显示在每个帖子上.任何帮助将不胜感激,我基本上只是复制/粘贴了Pieter的代码,并做了少许补充: