Method for automatically adding ellipsis when dedecms displays the title (cn_substr)

Source: Internet
Author: User

You all know how to modify dedecms's restricted title length and ellipsis. Sometimes, webpagesArticleWhen the title is too long, it will affect the appearance of the webpage. Therefore, we need to trim it to limit how many texts it only displays, and replace the extra content with a ellipsis. so how can we achieve this with dedecms? Several methods are listed below for your reference:

 

1. How to modify CSS: Here is the Title explanation: width: 120px; limited length, text-overflow: ellipsis: when the object text overflows, the omission mark is displayed ..., White-space: nowrap: forces the text to be displayed in a row. overflow: hidden: The overflow content is hidden. The method for modifying CSS is simple, but unfortunately, the text-overflow: ellipsis attribute is ineffective in Firefox.

2. How to modify the template: use [field: title function = '(strlen ("@ me")> 30? Cn_substr ("@ me", 30 )."..." : "@ Me") '/] replaces the original [field: Title/], and adds a judgment process when outputting the title. First, you can determine whether the title is greater than 30 bytes, if the value is greater than 30 bytes, only the length of 30 bytes is output, and the ellipsis is added. Title = "[field: Title/]" is not affected. When you move the cursor up, all the content of the title is displayed.

3. Add a function

Add a new function in include \ helpers \ string. helper. php.CodeAs follows:

/*** Chinese cut, the thumbnail ** @ access public * @ Param string $ STR refers to the string to be intercepted * @ Param int $ length intercepted by slen * @ Param int $ startdd start mark * @ Param string $ sq omitting character * @ return string */If (! Function_exists ('cn _ substr_sq ')){Function cn_substr_sq ($ STR, $ slen, $ startdd = 0, $ sq = "...") {$ sq = strlen ($ Str)> $ slen? "...":"";$ Text = cn_substr_utf8 ($ STR, $ slen, $ startdd). $ sq;Return $ text;}}

I put it in the string. Help. php file. This function depends on the cn_substr_utf8 function.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.