34?cn_substr("@me",30 )..." and save it.">
Home >CMS Tutorial >DEDECMS >How does DedeCMS determine if the brief title is empty and display the complete title?
How does DedeCMS determine if the simple title is empty and display the complete title?
Preface
I believe everyone has encountered it. When we use the DedeCMS system program to develop websites, we will encounter many restrictions due to web page layout design. The width of the article title requires a word limit. The usual method is to add a title attribute to the a tag so that the complete title will be displayed when the mouse is placed on it.
But the title is incomplete because some characters have been cut off. Here are several other ways to call the title. For example, when judging the title, DedeCMS will display the complete title when it judges that the abbreviated title is empty.
Recommended learning: 梦Weavercms
The specific method is as follows:
Method 1:
{dede:field name='array' runphp='yes'} if (@me['shorttitle']=='') @me=@me['title'];else @me=@me['shorttitle'];{/dede:field}
Method 2:
[field:array runphp='yes'] if (@me['shorttitle']=='') @me=@me['title'];else @me=@me['shorttitle'];[/field:array]
This method can be applied in the {dede:arclist} tag.
Method 3:
Sometimes the title is too long and displaying it all will cause layout confusion and affect the appearance. But the display part affects the user experience. We hope that when the title is within a certain length range, the full title will be displayed. When the title is out of date, only a certain length will be displayed, followed by an ellipsis, and then when the mouse is moved up, the entire content of the title will be displayed. In this way, it will not affect the layout. The layout also displays all the title content.
Here is a method that does not require modifying the program, but only modifies the template. For example, in the following title list, the longest title is 50 bytes, and only 30 bytes are displayed. The template code is as follows:
<ul> {dede:arclist titlelen='50' row='10'} <li><a title="[field:title /]" href="[field:filename /]">[field:title function='( strlen("@me")>30 ? cn_substr("@me",30)."..." : "@me" )'/]</a></li> {/dede:arclist} </ul>
Obviously, the key to solving the problem is to use [field :title function='( strlen("@me")>34 ? cn_substr("@me",30)."..." : "@me" ) ' /] replaces the original [field:title / ], there is an additional judgment process when outputting the title. First, judge whether the title is greater than 34 bytes. If it is greater, only the length of 30 bytes will be output, and an ellipsis will be added. Title="[field:title /]" will not be affected, and the entire content of the title will be displayed when the mouse is moved up.
Method 4:
In addition to the above methods of modifying the template, there are also methods such as programming or CSS. But for problems that can be solved through templates, programming is not necessary. The CSS method is as follows:
<a style="width:120px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden;" title="DedeCMS2007即将发布" href=" " >DedeCMS2007即将发布</a>
Explanation: width:120px; limited length, text-overflow:ellipsis: when the text in the object overflows, the omission mark is displayed..., white-space: nowrap: forces the text to be displayed in one line, overflow:hidden: overflow content is hidden. For more related usage tips, you can refer to this article: https://www.jb51.net/article/50258.htm
The CSS method is simpler than modifying the template. Unfortunately, the text-overflow:ellipsis attribute has no effect in Firefox. So, let’s use the above method of modifying the template.
I recently discovered another problem, dede title link, if it can be linked, if not, it will not be connected. Here is the solution:
{dede:list pagesize='15' orderby='weight' orderway='desc'} <dl> <dt>[field:pubdate function='strftime("%Y/%m/%d",@me)'/]</dt> <dd> [field:array runphp='yes'] if (@me['body']=='') @me=@me['title'];else{ @me = '<a href="'.@me['arcurl'].'" title="'.@me['description'].'" target="_blank">'.@me['title'].'</a>';}[/field:array] </dd> </dl> {/dede:list}
The above is the detailed content of How does DedeCMS determine if the brief title is empty and display the complete title?. For more information, please follow other related articles on the PHP Chinese website!