PC实用标签整理

PC实用标签整理

新手代码段

栏目标签 ==>

    {$CATEGORYS[$catid][catname]} 栏目名称
    {$CATEGORYS[$catid][url]} 目录url
    {$CATEGORYS[$catid]['letter']} 栏目拼音
    {$CATEGORYS[$catid]['description']} 栏目描述
    {$CATEGORYS[$catid][catid]} 栏目id
    {$CATEGORYS[$catid][module] 栏目所在的模块
    {$CATEGORYS[$catid][type]} 栏目类型
    {$CATEGORYS[$catid][modelid]} 栏目所属模型id
    {$CATEGORYS[$catid][style]} 栏目名称样式
    {$CATEGORYS[$catid][image]} 栏目图片
    {$CATEGORYS[$catid][catdir]} 栏目路径
    {$CATEGORYS[$catid][parentid]} 栏目的父id
    {$CATEGORYS[$catid][arrparentid]} 所有上级栏目ID
    {$CATEGORYS[$catid][parentdir]} 父栏目的路径
    {$CATEGORYS[$catid][child]} 是否有子栏目
    {$CATEGORYS[$catid][arrchildid]} 栏目的所有子栏目id
    {$CATEGORYS[$catid][items]} 栏目信息数
    {$CATEGORYS[$catid][ismenu]} 栏目是否显示导航
    {$CATEGORYS[$catid][catid]} 栏目id
    {$CATEGORYS[$catid][module]} 栏目所在的模块
    {$CATEGORYS[$catid][type]} 栏目类型
    {$CATEGORYS[$catid][modelid]} 栏目所属模型id
    {$CATEGORYS[$catid][catname]} 栏目名称
    {$CATEGORYS[$catid][style]} 栏目名称样式
    {$CATEGORYS[$catid][image]} 栏目图片
    {$CATEGORYS[$catid][catdir]} 栏目路径
    {$CATEGORYS[$catid][url]} 目录url
    {$CATEGORYS[$catid][parentid]} 栏目的父id
    {$CATEGORYS[$catid][arrparentid]} 所有上级栏目ID
    {$CATEGORYS[$catid][parentdir]} 父栏目的路径
    {$CATEGORYS[$catid][child]} 是否有子栏目
    {$CATEGORYS[$catid][arrchildid]} 栏目的所有子栏目id
    {$CATEGORYS[$catid][items]} 栏目信息数
    {$CATEGORYS[$catid][ismenu]} 栏目是否显示导航
    {$CATEGORYS[$CATEGORYS[$CAT[parentid]][parentid]][catname]} 上上级栏目名称
    {$CATEGORYS[$CATEGORYS[$CAT[parentid]][parentid]][url]} 上上级栏目链接

顶级父栏目 ==>

    $top_parentid //顶级父栏目id,(单页不支持需改写)
    $arrparentid //顶级父栏目数组

面包屑去除最后的“>” ==>

    {preg_replace('/( \> )$/', '', catpos($catid))}

获取缩略图 ==>

    {thumb($r[thumb], $width, $height)}

列表页展示当前位置 ==>

    <a href="{siteurl($siteid)}">首页 ></a> {rtrim(trim(catpos($catid))," > ")}

头部 ==>

    <meta charset={CHARSET}">
    <title>{if isset($SEO['title']) && !empty($SEO['title'])}{$SEO['title']}{/if}{$SEO['site_title']}</title>
    <meta name="keywords" content="{$SEO['keyword']}">
    <meta name="description" content="{$SEO['description']}">

截取字符 ==>

    {str_cut(strip_tags($r[content]),60,'...')}
    {str_cut(strip_tags($r[description]),60,'...')}

引入模板 ==>

    {template "content","header"}
    {template "content","footer"}

格式化时间 ==>

    时间戳转换 >> {date('Y-m-d H:i:s',$r[inputtime])}
    时间截取 >> {date('Y-m-d',strtotime($inputtime))}
    文章页时间 >> {$inputtime}

获取站点域名 ==> {siteurl($siteid)}


常用标签

调用导航列表

<ul>
{pc:content action="category" catid="0" siteid="$siteid" num="9" order="listorder ASC"}
    <li><a href="/">医院首页</a></li>
    {loop $data $r}
    <li><a href="{$r['url']}">{$r['catname']}</a></li>
    {/loop}
    {/pc}
</ul>

调用指定栏目的栏目列表

{pc:content action="category" catid="9" num="4" order="listorder ASC"}
    {loop $data $r}
    <li class="spc"><a href="{$r['url']}" title="{$r['catname']}" alt="{$r['catname']}">{$r['catname']}</a></li>
    {/loop}
    {/pc}

调用指定栏目的文章列表

{pc:content action="lists" catid="8" num="5" siteid="$siteid" start="1" order="id DESC"}
    {loop $data $r}
    <li>
        <a href="{$r['url']}" title="{$r['title']}" alt="{$r['title']}">&middot;  {$r['title']}</a>
        <span>{date('Y-m-d H:i:s',$r[inputtime])}</span>
    </li>
    {/loop}
    {/pc}

调用推荐位文章

pc:content action="position" posid="18" order="listorder DESC" num="5"}
    {loop $data $r}
    <li style="display:block;"><a href="{$r['url']}" title="{$r['title']}" alt="{$r['title']}">&middot; {$r['title']}</a><span>{date('Y-m-d',$r[inputtime])}</span></li>
    {/loop}
    {/pc}

调用指定栏目的热点文章

方式一:
{pc:content  action="hits" catid="15,16,17,18,19,20,21" order="weekviews DESC" num="4"}
    {loop $data $key $val}
    {/loop}
    {/pc}
方式二:
{pc:content action="hits" catid="9" order="weekviews DESC" num="6"}
    {loop $data $r}
    <li><a href="{$r['url']}" title="{$r['title']}" alt="{$r['title']}">&middot; {$r['title']}</a><span>{date('Y-m-d',$r[inputtime])}</span></li>
    {/loop}
    {/pc}

注意调用热点文章,需要在文章页模板添加一个js的API接口:
    JS ==> 放在body前面即可
        <script type="text/javascript" src="{JS_PATH}jquery.min.js"></script>
        <script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"></script></span>
    文章页显示浏览量的方式 ==> 4种
        点击率: <span id="hits"></span>
        今日浏览量: <span id="todaydowns"></span>
        本周浏览量: <span id="weekdowns"></span>
        本月浏览量: <span id="monthdowns"></span>

调用指定栏目的随机文章

{pc:content action="lists" catid="9" num="12" order="rand()" return="data"}
    {loop $data $r}
    <li><a href="{$r['url']}" title="{$r['title']}"> &middot;  {$r['title']}</a><span>{date('Y-m-d',$r[inputtime])}</span></li>
    {/loop}
    {/pc}

列表页 - 调用文章列表,带分页效果

{pc:content action="lists" catid="$catid" num="12" order="id DESC" page="$page"}
    {loop $data $r}
    <h3>
        <a href="{$r['url']}" title="{$r['title']}" alt="{$r['title']}">{$r['title']}</a>
        <span>{date('Y-m-d H:i:s',$r[inputtime])}</span>
        <div class="clear"></div>
    </h3>
    <p>{str_cut($r['description'],150,'')} ...<a href="{$r['url']}" title="{$r['title']}" alt="{$r['title']}"> [更多] </a></p>
    <div class="boundary"></div>
    {/loop}
    <div id="pages" class="text-c">{$pages}</div>
    {/pc}
    分页样式 ==>
        /*分页 id="pages"*/
        #pages{text-align: center;}
        #pages a{padding:0 10px;height: 30px;line-height: 30px;text-align: center; background: #e6e6e6;color: #333;display: inline-block;}
        #pages span{padding:0 10px;height: 30px;line-height: 30px;text-align: center; background: #006fcf;color: #fff;display: inline-block;}
        #pages a:hover{background: #006fcf;color: #fff;}

内容页 - 调用内容,并分页

<div class="content">
    {$content}
</div>
<div id="pages">{$pages}</div>
分页样式 ==> 同列表页 分页样式
    /*分页 id="pages"*/
    #pages{text-align: center;}
    #pages a{padding:0 10px;height: 30px;line-height: 30px;text-align: center; background: #e6e6e6;color: #333;display: inline-block;}
    #pages span{padding:0 10px;height: 30px;line-height: 30px;text-align: center; background: #006fcf;color: #fff;display: inline-block;}
    #pages a:hover{background: #006fcf;color: #fff;}

文章页上下篇

    <span class="prev">上一篇:<a href="{$previous_page[url]}">{$previous_page[title]}</a></span>
    <span class="next">下一篇:<a href="{$next_page[url]}">{$next_page[title]}</a></span>

让单页支持 $top_parentid变量

需要修改的文件 ==> 2个文件
    /phpcms/modules/content/class/html.class.php
    /phpcms/modules/content/index.php
修改代码 ==>
    }else{
        //单网页
        ……
        $parentid = $CATEGORYS[$catid]['parentid'];
        ……
        $SEO = seo($siteid, 0, $title,$setting['meta_description'],$keywords);
        ……
        //此处后加入内容
        //最顶级栏目ID
        $arrparentid = explode(',', $CAT['arrparentid']);
        $top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid;
    }

单页 关键词后台修改无效

需要修改的文件 ==> 2个文件
    /phpcms/modules/content/class/html.class.php
    /phpcms/modules/content/index.php
修改代码 ==>
        找到
    $SEO = seo($siteid, 0, $title,$setting['meta_description'],$keywords);
        替换成
    $SEO = seo($siteid, $catid, $title,$setting['meta_description'],$keywords);

PC循环栏目catid

{pc:content action="category" siteid="$siteid" catid="0" order="listorder DESC" num="20"}
    {loop $data $n $r}
        <li>
            <a href="{$r[url]}">
                {$n}{$r[catname]}
            </a>
        </li>
    {/loop}
    {/pc}

PC循环出顺序数字

{pc:content action="category" siteid="$siteid" catid="0" order="listorder DESC" num="20"}
    {php $number=1}
    {loop $data $r}
        <li>
            <a href="{$r[url]}">
                {$number}{$r[catname]}
            </a>
        </li>
        {php $number++}
    {/loop}
    {unset($number)}
    {/pc}

后台登陆验证码固定6666

文件目录 ==>
    /phpcms/modules/admin/index.php
修改代码 ==>
    $code = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
    if ($_SESSION['code'] != strtolower($code)) {
        $_SESSION['code'] = '';
        showmessage(L('code_error'), HTTP_REFERER);
    }
    //备注:将整段代码备注掉,登陆时就不需要验证码
    ------------------------------------
        将
    if ($_SESSION['code'] != strtolower($code)) {
        替换成
    if ($_SESSION['code'] != strtolower($code) && $code != '6666') {
        后台登陆验证码固定为6666

文章页 - 相关文章

{pc:content action="relation" relation="$relation" catid="$catid" num="5" keywords="$rs[keywords]"}
    {loop $data $r}
    <li>·<a href="{$r[url]}" target="_blank">{$r[title]}</a><span>({date('Y-m-d',$r[inputtime])})</span></li>
    {/loop}
    {/pc}

多栏目调用&多推荐位调用

调用需求 ==>
    文章范围为59 60 61三个栏目,并且推送到了2728两个推荐位;
    从第三条开始,连续调用7篇文章。
代码 ==>
    {pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posid in(27,28) and catid in(59,60,61)) order by listorder DESC" cache="3600" start="3" num="7" return="data" }
        {loop $data $n $r}
        <li>·<a target="_blank" href='{$r[url]}' title="{$r[title]}" style="color:Black;">{str_cut($r[title],22,'')}</a></li>
        {/loop}
        {/pc}

文章列表页调用关键字,或者首页调用关键字

{pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"}
    {loop $data $r}
    <a href="{$r[url]}">{$r[title]}</a>

    {php $keywords = explode(',',$r[keywords]);}
    <b>文章标签:</b>
    {loop $keywords $keyword}
    <a href="{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}" class="blue"> {$keyword}</a>
    {/loop}

    {/loop}
    {/pc}

    注意:
        explode(',',$r[keywords]);是将文章关键词通过英文逗号分离,也就是说每一篇文章都要以逗号间隔关键字,否则调用出来会是全部作为一个关键字。
        如果是空格间隔关键字,将explode(',',$r[keywords]);改成explode(' ',$r[keywords]);

编辑器上传图片自动使用标题作为alt参数

    一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js
        找到 accessKey:'T','default':'' 替换成 accessKey:'T','default':$('#title').val()
    二: 清除浏览器缓存

增加文章的随机点击数

文件 ==> /api/count.php
    找到50行的
    $views = $r['views'] +1
    修改为:
    $rand_nums=rand(79,186);
    $views = $r['views'] + $rand_nums;

备注 ==> 表示点击一次,增加79到186次不等

一级栏目 + 二级栏目

<div class="xw navbox">
    <ul class="inbk">
    {pc:content action="category" catid="0" num="10" siteid="$siteid" order="listorder ASC"}
        <li class="nli"><h3><a href="{APP_PATH}" class="home">返回首页</a></h3></li>
        {loop $data $r}
        <li class="nli">
            <h3>{$r[catname]}</h3>
            <ul class="sub-nav cf">
            {pc:content action="category" catid="$r[arrchildid]" num="10" siteid="$siteid" order="listorder ASC"}
                {loop $data $r}
                <li><a href="{$r[url]}">{$r[catname]}</a></li>
                {/loop}
                {/pc}
            </ul>
        </li>
        {/loop}
        {/pc}
    </ul>
</div>

备注 ==> 似乎有点问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值