Get the App
SLTechnology News&Howtos  ›  Servers  › 

Dedecms calls the method of body content field in the list page

Shulou Source: shulou.com Published: 2022-06-02 05:06:36 11月24日 Update

Editor to share with you how dedecms calls the body content field on the list page. I hope you will gain a lot after reading this article. Let's discuss it together.

How does dedecms invoke body content fields on the list page?

We all know that the optimization of description is also closely related to seo, and novices to seo often do not have this experience. It may be better not to write description, but there is a problem if you do not write description, that is, you cannot call up a brief introduction to the article on the article list page.

Such as the following code:

{dede:list pagesize='10'} [field:title/] [field:description/]... Author: [field:writer/] posted on: [field:pubdate function= "GetDateTimeMK (@ me)" /] comment: [field:scores/] Click: [field:click/] {/ dede:list}

Because the introduction of the article will be blank when you don't write description, which seriously affects the beauty and function of the page.

Here are some of my solutions.

We can intercept the first 100 words of the article as a brief introduction to the article, here we want to use a combination of two functions, cn_substr and html2text, to intercept the article after escaping. The test code: [field:body function= "cn_substr (html2text (@ me), 200)" /], it turns out it still doesn't work because body and description are not in the same table. So we have to start with the procedure.

Open extend.func.php under the include file and add the following code:

/ / get a single document bodyfunction GetOneArchiveBody ($aid,$length) {global $dsql;$aid = trim (ereg_replace ('[^ 0-9]','', $aid)); $body =''; $query = "Select art.body From `dede_ addonSecretle`art, `dede_ archives` arc where art.aid='$aid' and art.aid=arc.id"; $arcRow = $dsql- > GetOne ($query); if (! is_array ($arcRow)) {return $body } if (isset ($arcRow ['body'])) {$body = cn_substr (html2text ($arcRow [' body']), $length);} return $body;}

Call the template in the foreground:

{dede:list pagesize='10'} [field:title/] [field:id function= "GetOneArchiveBody (@ me,200)" /]. Author: [field:writer/] posted on: [field:pubdate function= "GetDateTimeMK (@ me)" /] comment: [field:scores/] Click: [field:click/] {/ dede:list} finished reading this article, I believe you have some understanding of dedecms's method of calling the body content field in the list page, want to know more about it, welcome to follow the industry information channel, thank you for reading!

Tags: Article content field method code introduction author article comment no beauty closely related one side two function foreground function single article finished that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info vpn Docker MariaDB