Home  >  Article  >  CMS Tutorial  >  How to use the DEDECMS extension tag

How to use the DEDECMS extension tag

藏色散人
藏色散人Original
2020-01-11 09:17:121929browse

How to use the DEDECMS extension tag

How to use the DEDECMS extension tag?

DDEECMS extension tag demonstration example

Recommended learning: DEMENCMS

We can look at a sample tag: demotag.lib .php,

if(!defined('DEDEINC')) 
{ 
exit("Request Error!"); 
} 
function lib_demotag(&$ctag,&$refObj) 
{ 
global $dsql,$envs; 
 
$attlist="row|12,titlelen|24"; 
FillAttsDefault($ctag->CAttribute->Items,$attlist); 
extract($ctag->CAttribute->Items, EXTR_SKIP); 
$revalue = ''; 
 
//------------------------------------------------------ 
$revalue = 'Hello Word!'; 
//------------------------------------------------------ 
return $revalue; 
} 
?>

We will find that the tag works and our content is output.

How to use the DEDECMS extension tag

$revalue = 'Hello Word!'; 
$revalue .=" 
Row:".$row.";TitleLen:".$titlelen;

How to use the DEDECMS extension tag

So we can see that this attribute has been created as a variable and assigned a value.

Next we can further modify this label.

function lib_writerarc(&$ctag,&$refObj)

Next we can write query statements and related functions for underlying template processing

$revalue = ''; 
$innertext = $ctag->GetInnerText(); 
$ctp = new DedeTagParse(); 
$ctp->SetNameSpace('field', '[', ']'); 
$sql = "SELECT * FROM dede_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row"; 
 
 
 
$dsql->Execute('me',$sql); 
while($rs = $dsql->GetArray('me')) 
{ 
 
$rs['title'] = cn_substr($rs['title'], $titlelen); 
 
$ctp->LoadSource($innertext); 
foreach($ctp->CTags as $tagid=>$ctag) { 
if(!emptyempty($rs[strtolower($ctag->GetName())])) { 
$ctp->Assign($tagid,$rs[$ctag->GetName()]); 
} 
} 
 
$revalue .= $ctp->GetResult(); 
}

Finally return this value return $revalue;

The entire file content is as follows:

if(!defined('DEDEINC')) 
{ 
exit("Request Error!"); 
} 
function lib_writerarc(&$ctag,&$refObj) 
{ 
global $dsql,$envs; 
 
$attlist="row|12,titlelen|24"; 
FillAttsDefault($ctag->CAttribute->Items,$attlist); 
extract($ctag->CAttribute->Items, EXTR_SKIP); 
$revalue = ''; 
$innertext = $ctag->GetInnerText(); 
$ctp = new DedeTagParse(); 
$ctp->SetNameSpace('field', '[', ']'); 
$sql = "SELECT * FROM dede_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row"; 
$dsql->Execute('me',$sql); 
while($rs = $dsql->GetArray('me')) 
{ 
 
$rs['title'] = cn_substr($rs['title'], $titlelen); 
 
$ctp->LoadSource($innertext); 
foreach($ctp->CTags as $tagid=>$ctag) { 
if(!emptyempty($rs[strtolower($ctag->GetName())])) { 
$ctp->Assign($tagid,$rs[$ctag->GetName()]); 
} 
} 
 
$revalue .= $ctp->GetResult(); 
} 
return $revalue; 
} 
?>

View and debug through dynamic browsing of the page?aid=3

{dede:writerarc row='10' titlelen='6'} 
[field:title/]  
{/dede:writerarc}

How to use the DEDECMS extension tag

The above is the detailed content of How to use the DEDECMS extension tag. 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