Home > CMS Tutorial > DEDECMS > body text

How does DedeCMS determine if the brief title is empty and display the complete title?

藏色散人
Release: 2019-12-19 09:27:23
Original
2479 people have browsed it

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}
Copy after login

Method 2:

[field:array runphp='yes'] if (@me['shorttitle']=='') @me=@me['title'];else @me=@me['shorttitle'];[/field:array]
Copy after login

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=&#39;50&#39; row=&#39;10&#39;}
     <li><a title="[field:title /]" href="[field:filename /]">[field:title function=&#39;( strlen("@me")>30 ? cn_substr("@me",30)."..." : "@me" )&#39;/]</a></li>
     {/dede:arclist}
</ul>
Copy after login

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>
Copy after login

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=&#39;15&#39; orderby=&#39;weight&#39; orderway=&#39;desc&#39;}
        <dl>
         <dt>[field:pubdate function=&#39;strftime("%Y/%m/%d",@me)&#39;/]</dt>
         <dd>
[field:array runphp=&#39;yes&#39;] if (@me[&#39;body&#39;]==&#39;&#39;) @me=@me[&#39;title&#39;];else{ @me = &#39;<a href="&#39;.@me[&#39;arcurl&#39;].&#39;" title="&#39;.@me[&#39;description&#39;].&#39;" target="_blank">&#39;.@me[&#39;title&#39;].&#39;</a>&#39;;}[/field:array]      
         </dd>
        </dl>
{/dede:list}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!