0712-2888027 189-8648-0214
微信公众号

孝感风信网络科技有限公司微信公众号

当前位置:主页 > 技术支持 > DedeCMS > dedecms中runphp=yes标签调用方法

dedecms中runphp=yes标签调用方法

时间:2024-05-17来源:风信官网 点击: 853次
在dedecms中如果有一些模板标签实现不了我逻辑我们可以直接在页面调用php标签了,我们只要在模板中使用runphp=yes然后就可以进入常用的php写法了,具体看一些例子。

runphp='yes'在循环中的应用。

 

 代码如下 复制代码
{dede:arclist row=14 titlelen=32 noflag='h'}
    <li><a href="[field:arcurl/]">[field:title/]</a>
 [field:id runphp='yes']
 if(@me==5){
  @me='选中';
 }else{
  @me='没选中';
 }
 [/field:id]

那么我们再来一些更高级的runphp=yes标签中调用其他field值

例子

 代码如下 复制代码

{dede:php}$GLOBALS['xxoo']=$refObj->Fields['fieldname']{/dede:php}
{dede:field.xxxx runphp="yes"}@me="test".@me."-test".$GLOBALS['xxoo'];{/dede:field.xxxx}

即,先开一个PHP的标签,把想赋的值替换给global变量。然后在另外的运行中将field值赋值给他。


如果是内容页使用以下代码:

 代码如下 复制代码

{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}


另一种使用方法:

{dede:field.id runphp=yes}
global $dsql;
$url="/";
$html=".html";
$sql1 = "SELECT id,typedir,sitepath,siteurl FROM dede_arctype where reid=3 and typename in(select typename from dede_arctype where id=".@me.")";
$dsql->execute('a',$sql1);
$row1=$dsql->getobject('a');
$url1=str_replace($row1->sitepath,"",$row1->typedir);
$siteurl=$row1->siteurl;
$sql2="select id,title,description,litpic from dede_archives where typeid=".$row1->id;
$dsql->execute('b',$sql2);
$rows=$dsql->GetTotalRow('b');
while($arr = $dsql->GetArray('b'))
{
$aa.= "<li>
<div class='zj_pic'><img src='http://ainaiyou.blog.163.com/blog/{$arr['litpic']}' height='136' width='112' /></div>
<div class='zj_detail'>
<h3> 姓名:{$arr['title']}</a></h3><p>{$arr['description']}... [<A href="http://www.ithov.net/.$siteurl.$url1.$url." {$arr['id']}".$html.">详细</A>]</p>
</div>
</li>";
}
@me=$aa;
{/dede:field.id}

{dede:field.id runphp=yes}
global $dsql;
$sql1="select id,typedir from dede_arctype where topid=0 and typename in(select typename from dede_arctype where id in(select typeid from dede_archives where id=".@me."))";
$dsql->execute('a',$sql1);
$row1=$dsql->getobject('a');

$sql2="select id,typedir,siteurl from dede_arctype where typename='媒体报道' and reid=".$row1->id;
$dsql->execute('b',$sql2);
$row2=$dsql->getobject('b');

$mtbd=str_replace("$row1->typedir","",$row2->typedir);
$siteurl=$row2->siteurl;
$url="/";
$html=".html";

$sql3="select * from dede_archives where typeid=".$row2->id;
$dsql->execute('c',$sql3);
$pub=array();
$rows=$dsql->GetTotalRow('c');
while($arr = $dsql->GetArray('c'))
{
 $arr1['pubdate'].=Mydate('y-m-d',$arr['pubdate']).".";
 $arr2['title'].=$arr['title'].".";
 $arr3['id'].=$arr['id'].".";
}
@me="";
$title=explode(".",$arr2['title']);
$pubdate=explode(".",$arr1['pubdate']);
$id=explode(".",$arr3['id']);

for($x=0;$x<$rows;$x++)
{
@me.="<li><a href="http://www.ithov.net/.$siteurl.$mtbd.$url.$id[$x].$html.">".$title[$x].$pubdate[$x]."</a></li>";
}

{/dede:field.id}
热门关键词: dedecms runphp=yes 标签调用
栏目列表
推荐内容
热点内容
展开