php - substr() 无法在 wordpress 小部件中修剪 the_content()

标签 php wordpress

<div class="wpex-recent-posts-content clr">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><p>
<?php
    $content = the_content();
    echo substr($content,0,100);
?>
</p>
</div>

此处 echo substr($content,0,100); 无法将内容从 0 裁剪到 100。这位于 my_theme/functions/widgets/widget-portfolio-posts- thumbs.php

最佳答案

试试这个:

$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 100);

关于php - substr() 无法在 wordpress 小部件中修剪 the_content(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22506239/

相关文章:

php - 使用 AJAX 的文本内容和文件上传

php - 实现报告卡生成系统

php - 如何在php mysql中从select语句中插入部分数据

php - 如何从 php 和 mysql 数据库创建图表和最终用户前端导航

linux - 即使插入证书后,永久链接仍指向 HTTP

php - 避免 yii2 中的 sql 注入(inject)

php - 从 MySQL 中的日期详细信息构建文本字符串

javascript - 只有 Javascript 代码来显示没有 onclick 的类

html - 如何更改我的 wordpress 网站上图像和文本的对齐方式?

php - 通过 $wpdb->query() 更新 Wpdb 不工作