OneThink友情链接插件使用!

OneThink友情链接插件使用:

直接安装插件就好,查看数据库会有:onethink_links 这个表:

写 links 标签,调用友情链接:

<?php
namespace CommonTag;
use ThinkTemplateTagLib;
class My extends TagLib{
    // 定义标签
    protected $tags = array(
        'links'=> array('attr'=>'type,row')
    );
    public function _links($attr,$content){
        //调用父类
        $type = isset($attr['type']) ? $attr['type'] : '1';
        $limit = isset($attr['row']) ? $attr['row'] : '5';
        // 组合PHP代码的字符串
        $str = '<?php ';
        $str .= '$where = array("type" =>'.$type.',"status"=>1,"order"=>0);';
        $str .= '$_links = M("links")->where($where)->order("sort desc")->limit('.$limit.')->select();';
        $str .= 'foreach($_links as $v):';
        $str .= 'extract($v);?>';
        $str .= $content;
        $str .= '<?php endforeach;?>';
        return $str;
    }
};

前台模板输出:

<links type='2' row='2'>
    <a href="{$link}">{$title}</a>
</links>

友情链接插件同样也支持上传图片,此功能后续!

原文地址:https://www.cnblogs.com/e0yu/p/7367740.html