Home > Article > CMS Tutorial > How does DEDECMS call the article TAG tag and add a link?
How does Dreamweaver DEDECMS call the article TAG tag and add a link?
How does Dreamweaver DEDECMS call the article TAG tag and add a link?
Recommended learning: 梦Weavercms
1. If it is a list page, use the following code:
[field:id runphp='yes'] global $cfg_cmspath; $tags = GetTags(@me); $revalue = ''; $tags = explode(',', $tags); foreach($tags as $key => $value){ if($value){ $revalue .= '<a href="'.$cfg_cmspath.'/tags.php?/'.$value.'/">'.$value.'</a> '; } } @me = $revalue; [/field:id]
2. If it is a content page, use the following code :
{dede:field.id runphp='yes'} global $cfg_cmspath; $tags = GetTags(@me); $revalue = ''; $tags = explode(',', $tags); foreach($tags as $key => $value){ if($value){ $revalue .= '<a href="'.$cfg_cmspath.'/tags.php?/'.$value.'/">'.$value.'</a>, '; } } @me = $revalue; {/dede:field.id}
Code explanation
In fact, only three knowledge points are used here:
1. Use the built-in GetTags function to obtain the TAG list corresponding to the document;
2. Split the obtained value into an array using the half-width comma (,) as the standard;
3. Loop through the array elements, output the corresponding value and add a link;
At the same time, for better compatibility, the global $cfg_cmspath; method is also used here to load the program installation directory in the basic system parameters, which is used to automatically be compatible with sites installed in subdirectories when attaching links.
The above is the detailed content of How does DEDECMS call the article TAG tag and add a link?. For more information, please follow other related articles on the PHP Chinese website!