Home  >  Article  >  CMS Tutorial  >  How dedecms calls the body content field on the list page

How dedecms calls the body content field on the list page

藏色散人
藏色散人Original
2019-12-14 09:58:211992browse

How dedecms calls the body content field on the list page

dedecmsHow to call the body content field on the list page?

We all know that the optimization of description is closely related to seo. Newbies to seo often have no experience in this area. It may be better not to write description, but there will be a problem if not to write description. , that is, the introduction of the article cannot be called up on the article list page.

Recommended learning: 梦Weavercms

For example, the following code:

{dede:list pagesize='10'}
  
[field:title/]
  
[field:description/]...
  
作者:[field:writer/]
  
发表于:[field:pubdate function="GetDateTimeMK(@me)"/] 评论:[field:scores/] 点击:[field:click/]
  
{/dede:list}

Because no description is written, the article introduction will be blank, which will seriously affect Improves the beauty and functionality of the page.

Here are some of my solutions.

We can intercept the first 100 words of the article as the article introduction. Here we need to use two functions cn_substr and html2text in combination to escape the article and intercept it. Test code: [field:body function="cn_substr(html2text(@me),200)"/], it turns out that it still doesn't work because body and description are not in the same table. So I had to start with the program.

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

//获取单篇文档body
function GetOneArchiveBody($aid,$length)
{
global $dsql;
$aid = trim(ereg_replace('[^0-9]','',$aid));
$body = '';
$query = " Select art.body From `dede_addonarticle` 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 in the foreground template:

{dede:list pagesize='10'}
  
[field:title/]
  
[field:id function="GetOneArchiveBody(@me,200)"/]...
  
作者:[field:writer/]
  
发表于:[field:pubdate function="GetDateTimeMK(@me)"/] 评论:[field:scores/] 点击:[field:click/]
  
{/dede:list}

The above is the detailed content of How dedecms calls the body content field on the list page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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