我想在锚标签中显示帖子的一些内容并显示为链接但我使用的wp_trim_words功能我不知道如何允许html标签.
$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';
$content = wp_trim_words( get_the_content(), 50, $more );
echo do_shortcode($content);
Run Code Online (Sandbox Code Playgroud)
@dingo_d忘了在代码中添加wpautop().只需使用下面的代码.
$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';
echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( wpautop(get_the_content()) ), 100, $more ) ) );
Run Code Online (Sandbox Code Playgroud)
啊啊啊我傻了。这将起作用(已测试):
$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';
echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( get_the_content() ), 50, $more ) ) );
Run Code Online (Sandbox Code Playgroud)
我花了一段时间才想起wp_trim_words()从内容中删除了所有标签,因此您的 HTML 没有显示。所以我做了一些挖掘并发现了这个宝石:
WordPress 轨道票#29533。
希望这可以帮助。抱歉之前造成的混乱:)
| 归档时间: |
|
| 查看次数: |
4122 次 |
| 最近记录: |