循环标签
常用变量标签
链接地址 | {$v[url]} |
标题 | {$v[title]} |
描述 | {$v[description]} |
添加时间 | {date('Y-m-d',$v['inputtime'])} |
更新时间 | {date('Y-m-d H:i:s',$updatetime)} |
缩略图 | {get_thumb($v['thumb'])} |
内容 | {$v[content]} |
点击量 | {$v[click]} |
普通列表
<ul> {m:lists field="title,color,url,thumb,description,inputtime" catid="$catid" limit="5" page="page"} {php $total = count($data);} {loop $data $v} <li><a href="{$v[url]}"> <div class="textlist-l"> <dt>{title_color($v['title'], $v['color'])}</dt> <dd>{$v[description]}</dd> <p>查看详情 ></p> </div> <div class="newtime transition"><p><span>{date('d',$v['inputtime'])}</span>{date('Y-m',$v['inputtime'])}</p></div> </a></li> {/loop} </ul> <div class="model_page hidden-xs{if $total} yc{/if}"> {$pages} </div>
可能有的参数 | |
field | field="title,thumb,catid,url" |
catid | catid="1" |
modelid | modelid="1" |
thumb | thumb="1" |
flag | flag="1"。置顶[1] 头条[2] 特荐[3] 推荐[4] 热点[5] 幻灯[6] 跳转[7] |
where | where="nickname='admin'" |
order | order="RAND()",order="updatetime desc" |
limit | limit="10" |
page | page="page" |
return | return="nav_data" |
热门列表
{m:hits field="title,url" catid="$catid" limit="10"} {php $n=0} {loop $data $v} {$n++} <div class="item one{if $n<2} first{/if} clearfix"> <i class="num{if $n<3} fn{/if}">{$n}</i> <div class="title"> <a target="_blank" href="{$v[url]}" title="{$v[title]}"> {$v[title]} </a> </div> </div> {/loop}
子栏目列表
{php $r = get_childcat($catid);} {loop $r $v} <li><a href="{$v[pclink]}"{if $catid==$v['catid']} class="ez"{/if}>{$v[catname]}</a></li> {/loop}
友情链接列表
{m:link field="url,logo,name" limit="20"} {loop $data $v} <li><a href="{$v[url]}" target="_blank">{$v[name]}</a> </li> {/loop}
全站TAG标签
{m:tag field="id,tag,total" limit="20"} {loop $data $v} <li><a href="{U('search/index/tag',array('id'=>$v['id']))}" target="_blank">{$v[tag]}</a></li> <li><a href="{tag_url($v['id'])}" target="_blank">{$v[tag]}({$v[total]})</a></li> {/loop}
轮播图列表
{m:banner field="title,image,url" typeid="1" limit="3"} {loop $data $s=>$v} <div><a href="{$v[url]}"><img src="{$v[image]}"></a></div> {/loop}
同模型下的相关内容
{m:relation field="id,title,catid,thumb,stars,filesize,version" modelid="$modelid" id="$id" limit="12"} {loop $data $v} <div class="item clearfix"> <a href="{U('mobile/index/show', array('catid'=>$v['catid'],'id'=>$v['id']))}" class="detail clearfix"> <img src="{if !empty($v['thumb'])}{$v[thumb]}{else}{SITE_URL}skin/img/loading-1.gif{/if}" width="64" class="icon" alt="{$v[title]}"> <div class="body"> <div class="title">{$v[title]}</div> <div class="row"> <span class="s{$v[stars]}"></span> </div> <div class="row">{get_catname($v['catid'])} | {$v[filesize]} | {$v[version]}</div> </div> </a> </div> {/loop}
某文章内的标签
{m:centent_tag modelid="$modelid" id="$id" limit="10"} {loop $data $v} <span class='item'><a href='{U('search/index/tag',array('id'=>$v['id']))}' target='_blank'>{$v[tag]}</a></span> <span class='item'><a href='{tag_url($v['id'])}' target='_blank'>{$v[tag]}</a></span> {/loop}
多图上传调用
{php $pictures = string2array($jietu);} {loop $pictures $b} <li><img src="{$b[url]}" class="item-pic" width="320" alt="{$b[alt]}" ></li> {/loop}
自定义数组循环
{php $lmarr = array(5,16,15,14,13,12,11,10,9);} {loop $lmarr $s=>$v} //里面可以插入list循环列表 <li><a target="_blank" href="javascript:void(0);"{if !$s} class="active"{/if} title="{get_catname($v)}">{get_catname($v)}</a></li> {/loop}
自建专题频道页循环
<div class="spl-box m-box clearfix"> <div class="inner clearfix"> <?php yzm_base::load_sys_class('page','',0); $zttotal = D('zt')->where(array('status'=>1))->total(); $ztpage = new page($zttotal, 15); $ztdata = D('zt')->where(array('status'=>1))->order('id DESC')->limit($ztpage->limit())->select(); $pages = $ztpage->getfull(); ?> {loop $ztdata $v} <div class="item"> <a target="_blank" href="{U('zt/index/lists',array('id'=>$v['id']))}" title="{$v[title]}"><img src="{if !empty($v['catimg'])}{$v[catimg]}{else}{STATIC_URL}images/nopic.jpg{/if}" width="350" height="160" alt="{$v[title]}"/></a> <div class="body"> <div class="title"> <a target="_blank" href="{U('zt/index/lists',array('id'=>$v['id']))}" title="{$v[title]}">{$v[title]}</a> </div> <p> {$v[msg]}<a target="_blank" href="{U('zt/index/lists',array('id'=>$v['id']))}" title="{$v[title]}">详情>></a></p> </div> </div> {/loop} </div> <div class="paginate clearfix">{if $zttotal>16}{$pages}{/if}</div> </div>
在某个文章栏目中列出另一个下载栏目中TAG相关的产品
<?php $tag_content = D('tag_content'); //如果是下载模型的相关文章内容,这个地方就要改为下载模型ID $res = $tag_content->field('tagid')->where(array('modelid'=>1,'aid'=>$id))->limit(10)->select(); if(!empty($res)){ $tagid = array(); foreach($res as $val){ $tagid[] = $val['tagid']; } //下载 $lmid=get_category(相关下载栏目ID, 'arrchildid'); $res = $tag_content->field('aid')->where('modelid=3 AND catid IN ('.$lmid.') AND tagid IN ('.implode(',', $tagid).')')->group('aid')->limit(16)->order('aid DESC')->select(); $ids = array(); foreach($res as $val){ //如果是下载模型下的 相关文章内容,则要添加上这句。 //去除当前的内容ID //if($val['aid'] == $id) continue; $ids[] = $val['aid']; } if(!empty($ids)){ $xg1 = D('download')->field('title,thumb,url,version,filesize,stars')->where('status=1 AND id IN ('.implode(',', $ids).')')->order('id DESC')->limit(15)->select(); } //文章 $lmid2=get_category(相关文章栏目ID, 'arrchildid'); $res1 = $tag_content->field('aid')->where('modelid=1 AND catid IN ('.$lmid2.') AND tagid IN ('.implode(',', $tagid).')')->group('aid')->limit(13)->order('aid DESC')->select(); $ids1 = array(); foreach($res1 as $val){ //去除当前的内容ID if($val['aid'] == $id) continue; $ids1[] = $val['aid']; } if(!empty($ids1)){ $xg = D('article')->field('title,url')->where('status=1 AND id IN ('.implode(',', $ids1).')')->order('id DESC')->limit(12)->select(); } } ?> {if isset($xg1)} {loop $xg1 $v} <div class="item"> <a target="_blank" href="{$v[url]}" title="{$v[title]}"><img src="{if !empty($v['thumb'])}{$v[thumb]}{else}{SITE_URL}skin/img/loading-1.gif{/if}" width="96" height="96" alt="{$v[title]}"/></a> <div class="body"> <div class="title"> <a target="_blank" href="{$v[url]}" title="{$v[title]}"> {$v[title]} </a> </div> <div class="row"><span class="s{$v[stars]}"></span></div> <div class="row"> {$v[filesize]} / {$v[version]} </div> </div> </div> {/loop} {/if} {if isset($xg)} {loop $xg $v} <li><i class="dot"></i><a target="_blank" href="{$v[url]}">{$v[title]}</a></li> {/loop} {/if}
全站最近更新
{m:all field="title,url,inputtime" limit="10"} {loop $data $k=>$v} {php $k=$k+1;} <li><em>{$k}</em><span class="date">{date('m-d',$v['inputtime'])}</span><a href="{$v[url]}" title="{$v[title]}" target="_blank">{$v[title]}</a></li> {/loop} /*函数*/ public function all($data) { $where = isset($data['allsite']) ? array('status'=>1) : array('siteid'=>get_siteid(), 'status'=>1); $field = isset($data['field']) ? $data['field'] : 'modelid,catid,id,userid,username,title,inputtime,updatetime,url,thumb,issystem'; $order = isset($data['order']) ? $data['order'] : 'allid DESC'; $limit = isset($data['limit']) ? $data['limit'] : '20'; return D('all_content')->field($field)->where($where)->order($order)->limit($limit)->select(); }
自定义文章内容页图片集分页功能
//处理图片集 $arr = string2array($tu); $page = isset($_GET['page']) ? max(intval($_GET['page']), 1) : 1; $total_page = count($arr); $off = $page-1<$total_page ? $page-1 : $total_page-1; $pr = $page-1; $pn = $page+1; //不让页码超出最大页 if($page>$total_page){ redirect(U('mobile/index/init')); exit; } //每页显示的图片 if($page==$total_page){ if(strpos($next,'已经是最后一篇')!==false){ echo '<a href="?page='.($page+1).'" title="下一页"><img src="'.$arr[$off]['url'].'" alt="'.$title.' 第'.$page.'页"></a>'; }else{ echo str_replace(['">','</a>'],['" title="','"><img src="'.$arr[$off]['url'].'"></a>'],$next); } }else{ echo '<a href="?page='.($page+1).'" title="下一页"><img src="'.$arr[$off]['url'].'" alt="'.$title.' 第'.$page.'页"></a>'; } //分页 <div class="mb-pages"> <ul class="cl"> {if $page<=1}<li class="no-page"><a>上一页</a></li>{else}<li><a href="?page={$pr}">上一页</a></li>{/if}<li class="num-page"><span>{$page}</span><font>/{$total_page}</font></li>{if $page>=$total_page}<li class="no-page"><a>下一页</a></li>{else}<li><a href="?page={$pn}">下一页</a></li>{/if}</li> </ul> </div>
最新评论标签
{m:comment_newest limit="10"} <ul class="yzm-comment-list"> {loop $data $v} <li> <a href="{$v[url]}" title="{$v[title]}">{$v[title]}</a> <p><em>{if $v['userid']}{$v[username]}{else}网友评论{/if}</em>:{$v[content]}</p> </li> {/loop} </ul> /*函数*/ public function comment_newest($data) { $limit = isset($data['limit']) ? $data['limit'] : '20'; return D('comment')->field('userid,username,userpic,inputtime,content,title,url,catid,modelid')->join('yzmcms_comment_data b ON yzmcms_comment.commentid=b.commentid')->where('yzmcms_comment.siteid='.get_siteid().' AND `status`=1')->order('id DESC')->limit($limit)->select(); }
分页显示
{$pages} /*函数*/ public function pages() { if(!is_object($this->page)) return ''; //当前页:$this->page->getpage(); return '<span class="pageinfo">共<strong>'.$this->total.'</strong>条记录</span>'.$this->page->getfull(false); }
留言列表
{m:guestbook page="page" limit="5"} {loop $data $v} <div class="yzm-book-list"> <p class="yzm-book-head"> <strong>作者</strong>:{$v[name]}, <strong>留言主题</strong>:{$v[title]} <span>[{date('Y-m-d H:i:s',$v['booktime'])}]</span> </p> <p class="yzm-book-content"><strong>内容</strong>:{$v[bookmsg]}</p> <!-- 管理员回复 start --> {loop $v['admin_reply'] $v} <p class="yzm-book-content"><strong style="color:#de4c1c">管理员回复</strong>:{$v[bookmsg]}</p> {/loop} <!-- 管理员回复 end --> </div> {/loop} {if empty($data)}<div class="yzm-book-list"><p>暂无留言!</p></div>{/if} <div id="page">{$pages}</div>
评论列表标签
{m:comment_list modelid="$modelid" catid="$catid" id="$id" limit="20"} <div class="yzm-comment-list-top">共 {get_comment_total($id, $catid, $modelid)} 条评论,<a href="{U('comment/index/more', array('sign'=>$modelid.'_'.$id))}" target="_blank">查看全部</a></div> <div class="yzm-comment-list-body"> <ul> {loop $data $v} <li> <a class="user_pic" href="{U('member/myhome/init', array('userid'=>$v['userid']))}" target="blank"><img src="{if !empty($v['userpic'])}{$v[userpic]}{else}{STATIC_URL}images/default.gif{/if}" height="35" width="35"></a> <div class="yzm-comm-right"> <a class="user_name" href="{U('member/myhome/init', array('userid'=>$v['userid']))}" target="blank">{$v[username]}</a> <p>{nl2br($v['content'])}</p> <p><span class="comm_time">{date('Y-m-d H:i:s',$v['inputtime'])}</span> <a href="javascript:toreply('{$v[id]}');" class="comm_a">回复</a></p> <div id="rep_{$v[id]}" class="none"> <form action="{U('comment/index/init')}" method="post" onsubmit="return check_rep(this)"> <input type="hidden" name="modelid" value="{$modelid}"> <input type="hidden" name="catid" value="{$catid}"> <input type="hidden" name="id" value="{$id}"> <input type="hidden" name="title" value="{$title}"> <input type="hidden" name="url" value="{$url}"> <input type="hidden" name="reply" value="{$v[id]}"> <input type="hidden" name="reply_to" value="{$v[username]}"> <textarea name="content" class="textarea textarea2" placeholder="我来说两句~"></textarea> {if $site['comment_code']} <span class="yzm-comment-reply-code"><img src="{U('api/index/code')}" onclick="this.src=this.src+'?'" title="看不清?点击更换"><input type="text" name="code" placeholder="请输入验证码" required="required"></span> {/if} <input type="submit" class="yzm-comment-submit static" name="dosubmit" value="提交"> </form> </div> </div> </li> {/loop} {if empty($data)}<li>这篇文章还没有收到评论,赶紧来抢沙发吧~</li>{/if} </ul>
评论排行榜标签
{m:comment_ranking modelid="1" limit="10" cache="3600"} {loop $data $v} <li><a href="{$v[url]}" title="{$v[title]}">{$v[title]}</a></li> {/loop}
内容归档标签
{m:content_archives modelid="$modelid" type="2" limit="10" cache="3600"} {loop $data $v} <li><a href="{U('search/index/archives',array('pubtime'=>$v['inputtime']))}" target="_blank">{$v[pubtime]}({$v[total]})</a></li> {/loop} /*函数*/ public function content_archives($data) { $modelid = isset($data['modelid']) ? intval($data['modelid']) : 1; $type = isset($data['type']) ? intval($data['type']) : 1; $limit = isset($data['limit']) ? $data['limit'] : '20'; if(!$this->_set_model($modelid)) return false; $format = $type == 1 ? '%Y-%m' : '%Y年%m月'; return $this->db->field("FROM_UNIXTIME(inputtime, '$format') AS pubtime, count(*) AS total,inputtime")->where('`status`=1')->group("FROM_UNIXTIME(inputtime, '$format')")->order('pubtime DESC')->limit($limit)->select(); }