Dede Autoindex auto-increment label usage

Source: Internet
Author: User

1

<Ul> {Dede: arclist ROW = '6' titlelen = '60' orderby = 'pubdate' typeid = '1' idlist = ''channelid = '1 '}
<Li>
[Field: Global name = Autoindex/]
[Field: Global name = Autoindex runphp = "yes"] @ me = @ me + 5; [/field: Global]
[Field: Global name = Autoindex runphp = "yes"] (@ me % 2 = 0 )? @ Me = "|": @ me = ""; [/field: Global] [field: textlink/]

[Field: Global name = Autoindex runphp = "yes"] (@ me! = 8 )? @ Me = "|": @ me = ""; [/field: Global]
This label is null when Autoindex is equal to 8; otherwise, it is "| ".
</LI>
{/Dede: arclist}
</Ul>

2
In the {Dede: arclist/} tag, we all know that there is a [field: Global. autoindex/], this variable is + 1 for every row generated, so many people want to add this function to the {Dede: SQL/} tag. Many friends asked questions, I will definitely think that the official team will not do this. In fact, the official team will hope that everyone can share this kind of tips and experience on usage and development. In fact, this is very simple, you can find out by yourself.
Next we will start to add this small extension. We know that in v5.3, the woven dream labels have been separated, that is, labels like arclist can be modified or developed by ourselves, the directory where these labels are stored is under the/include/taglib folder. We can see the file name, so we can easily know the relationship between these tag names and labels.
Now we need to modify the {Dede: SQL/} tag, so we can modify the SQL. Lib. php file.
After opening the code, we can find the 34th lines, that is, the code.
$ CTP-> loadsource ($ innertext );
Add the following code below:
$ Globals ['autoindex'] = 0;
This Code defines a global variable with a value of 0. Next we only need to modify the following code:
While ($ ROW = $ dsql-> getarray ($ thisrs ))
{
$ Sqlct ++;
Foreach ($ CTP-> ctags as $ tagid => $ CTAG ){
If (! Empty ($ row [$ CTAG-> getname ()]) {$ CTP-> assign ($ tagid, $ row [$ CTAG-> getname ()]);}
}
$ Globals ['autoindex'] ++; // Add 1 to each loop and parse it.
$ Revalue. = $ CTP-> getresult ();
}
In this way, the [field: Global. Autoindex/] label can be used in {Dede: SQL/}. Let's take an example:
{Dede: SQL = 'select * from [url = mailto: #@__ Archives] #@__ archives '[/url]}
[Field: Global. Autoindex/]-[field: Title/] </BR>
{/Dede: SQL}
How is it? It's quite easy. In fact, there are still many such extensions. You can try them yourself.

You can write it like this:
{Dede: Global name = 'B' runphp = 'yes '}
Ob_start ();
Extract ($ globals, extr_skip );
//-----------------------
// The following is any PHP code
Print_r ($ this-> refobj-> fields); // test the field array for calling the current document class (only PhP5 is supported)

//----------------------
// Return the value to the tag itself
@ Me = ob_get_contents ();
Ob_clean ();
{/Dede: Global}

Of course, you want to support <? PHP?> This syntax also works. Modify the template class and set <? Replace PHP
{Dede: Global name = 'B' runphp = 'yes '}
Ob_start ();
Extract ($ globals, extr_skip );

Put?> Replace
@ Me = ob_get_contents ();
Ob_clean ();
{/Dede: Global}

Another way is to customize a PHP tag.
Copy Code <? PHP
If (! Defined ('deinc') Exit ('request error! ');

Function lib_php (& $ CTAG, & $ refobj)
{
$ Phpcode = trim ($ CTAG-> getinnertext ());
If ($ phpcode = '') return '';
Ob_start ();
Extract ($ globals, extr_skip );
@ Eval ($ phpcode );
$ Revalue = ob_get_contents ();
Ob_clean ();
Return $ revalue;
}

?>

Save the code

Include/taglib/PHP. Lib. php

In this way, use
{Dede: PhP}
// Any PHP code can be used here, but note that if there is an include file, dederoot must be used as the import directory
// For example, reuqire_once (dederoot. '/xxx. Inc. php ');
{/Dede: PhP}

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.