【发布时间】:2017-12-14 14:16:46
【问题描述】:
我在 wordpress 网站 (front-page.php) 上有一个代码,如果文本超过 35 个字符,它会剪切文本并在标题上添加“...”。 剪切是可以的,但点总是可见的。是否可以仅在剪切文本时添加? 谢谢!
<div class="bxpd">
<h2><span><?= substr($post_title,0,35); ?></span>
<a href="<?= get_post_permalink($post_id); ?>">
<?= substr($postData->post_title, 0, 35)."..."; ?>
</a>
</h2>
<p><?= substr($postData->post_content,0,strpos($postData->post_content, ' ', 150))."..."; ?> </p>
</div>
【问题讨论】:
-
如果原始长度大于 35,则将变量设置为 true。仅当该变量为 true 时才有条件地显示点
标签: php html wordpress substr strpos