The DEDECMS homepage calls the single-page document content and filters HTML content.

Source: Internet
Author: User
On the DEDECMS homepage, replace the single-page document content with the document id!

The weimeng dedecms website homepage calls the single-page document content and filters the html content:

1. the called Statement

{dede:sql sql="SELECT body FROM `dede_sgpage` where aid = 1" }[field:body function="htmlspecialchars(cn_substr(@me,130))"/]{/dede:sql}

Where:

{dede:sql sql="SELECT body FROM `dede_sgpage` where aid = 1" }

SQL = "SELECT body here the body is the content of the article, FROM 'dede _ sgpage' here dede_sgpage this is a single-page document archived data table, this is the DedeCms 5.6 project, other versions are defined by the table name. where aid = 7″ here aid = 7 is the id of your single-page document. which single-page document content do you need to call, replace this with the document id!

[field:body function="htmlspecialchars(cn_substr(@me,130))"/]

Field: body the body here is the content of the article. (cn_substr (@ me, 130) here, 130 is the number of words you want to display the content. you can adjust it by yourself.

However, there is a problem. Even html is intercepted. To filter it out, use

{dede:sql sql="SELECT body FROM `dede_sgpage` where aid = 1" }[field:body function="htmlspecialchars(cn_substr(Html2text(@me),750))"/]{/dede:sql}

The Html2text () function removes the html tag code.

The cn_substr (str, 80) function intercepts the string length.

How can I call the database content at will? For example, we all know that the website of Zhimeng template has a channel model with the function of adding a single-page document. but how can we call the content of a single-page document on the homepage, now I will explain how to use it:

1. add a single-page document to the single-page document management page on the homepage. enter the content you want to generate in the content editing box.

2. add the SQL Universal tag where you need to call a single-page document

{dede:sql sql=”select body from dede_sgpage where aid=2″}[field:body /]{/dede:sql}

I believe that those who are familiar with the SQL language can easily understand the meaning of this sentence. In fact, it means to select the body field input of the data table dede_sgpage. aid = 2 indicates that the document ID number on the single page is created, and you can modify it when using it.

This SQL tag sample code is also used.

Copy the code as follows:

{dede:sql sql="select content from dede_arctype where id=2"}[field:content function=cn_substr(Html2Text(@me),600)/]{/dede:sql}

According to the above example, it should be well understood. here we mainly describe that cn_substr indicates intercepting 600 characters, that is, 300 Chinese characters. Html2Text: filters out characters containing HTML and only displays the text.

In fact, in addition to the above example, in the Dede system, I can freely use SQL statements to make more personalized calls with the dream tag. Their basic reference formats are:

Copy the code as follows:

{Dede: SQL = "select field From table name where condition statement"} [field: field name/] {/dede: SQL}

From the above basic format, we can basically convert a call tag of the call Document List, the code is:

Copy the code as follows:

{dede:sql sql="select * From dede_archives limit 10"}
  • ·[field:title/]
  • {/dede:sql}

    We can see that the underlying template address of the above document link is dynamic, so how do we convert it and link it to the static address? here we only need to [field: id/]. the complete code after conversion is:

    Copy the code as follows:

    {dede:sql sql="SELECT * FROM dede_archives limit 10"}
  • ·[field:title function=cn_substr(@me,30,0)/]
  • {/dede:sql}

    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.