Weave Dream Dedecms Call database arbitrary content method with SQL statement

Source: Internet
Author: User

Weaving dream Dedecms gives us a lot of call tags, for us to invoke a variety of data, but to provide more tags, there is no time to meet us, then we can use the SQL statement, the flexibility to call the content we need.

How do I invoke the contents of a database arbitrarily? To give an example: we all know that there is a channel model inside the Dede has the ability to add a single-page document, but how to invoke the content of a single-page document on the homepage, and now tell you how to use:

1. Home in the background single page document management to add a single page document, the Content edit box to enter the content you want to generate.

2. Add a SQL Universal label where you need to invoke a single-page document {dede:sql sql= "select Body from Dede_sgpage where Aid=2″}[field:body/]{/dede:sql} It is easy to understand the meaning of a friend who is familiar with the SQL language. The meaning is to choose the data table dede_sgpage the Body field input, aid=2 here 2 means you create a single page document ID number, you use the corresponding changes can be made.

Another example of this SQL tag sample code

{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 is the main explanation of CN_SUBSTR that the interception of 600 characters is 300 kanji. The Html2text representative filters out characters that contain HTML and displays only text.

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

{dede:sql sql= "select  field from table name ' WHERE Condition statement '}[field: Field name/]{/dede:sql}

By this basic format, we can basically convert a call tag that calls a list of documents, with the following code:

{dede:sql sql= "select  * from dede_archives  limit"}<li>•  <href= "/plus/view.php?aid=[field:id/">[field:title/]  </a></li>{/dede:sql}

You see the above document link of the underlying template address is dynamic, then we how to do the conversion, let him link to the static address, here we only need to convert [Field:id/], the full code after the conversion is:

{dede:sql sql= "select * from Dede_archives limit"}<Li>·<ahref= "[Field:id runphp= ' yes '] [email protected]; @me ="; $url =getonearchive ($id); @me = $url [' Arcurl ']; [/field:id] "title= "[field:title/]"Target= "_blank">[Field:title function=cn_substr (@me, 30,0)/]</a></Li>{/dede:sql}

Transferred from: http://www.dedeadmin.com/?p=1602

Weave Dream Dedecms Call database arbitrary content method with SQL statement

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.