gpt4 book ai didi

php - if条件限制wordpress标题中的字数

转载 作者:行者123 更新时间:2023-12-02 07:46:00 24 4
gpt4 key购买 nike

我编写了这段代码来遍历我博客上最新的 6 篇文章,并将它们显示在一个特殊的框中,但是有一个小问题,当我写更长的标题时,标题会移动到下一行。我无法增加标题 div 的宽度,所以我需要编写一个 if 条件来显示“...”,如果标题在假设 20 个字符后移动到下一行。

<div id="freshlyWrapper">
<div id="freshlyposts">
<?php
$freshlyIonised = new WP_Query();
$freshlyIonised->query('category_name=FreshlyIonised&showposts=6');
while($freshlyIonised->have_posts()):
$freshlyIonised->the_post();
?>
<div class="freshlyionisedbox"><h3><a style='text-decoration: underline; color: #000;' href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

最佳答案

有一个更好的方法,使用 CSS:

DIV.freshlyionisedbox {
border: 1px solid #000000;
white-space: nowrap;
width: 150px;
overflow: hidden;
text-overflow: ellipsis;
}

这样做的好处是您的页面的语义内容得以保留,您不必猜测在特定像素数下用户屏幕上可以容纳多少个字符。

关于php - if条件限制wordpress标题中的字数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6997427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com