ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
> 插件说明:用于会员对cms的内容进行收藏 >[tip] 安装前,请先安装【cms插件】和【会员插件】 #### 效果如下: ![](https://img.kancloud.cn/4e/b1/4eb17ed55e2fa4c911008c428b5d7885_295x164.png) #### 1.在需要收藏按钮的模板页面加下以下html代码(具体样式自行调整) ``` <link rel="stylesheet" href="__STATIC__/common/font/iconfont.css"> <style type="text/css"> .favorite-box{text-align: center;} .favorite-box span{font-size: 14px;line-height: 20px;display: block;} .favorite-btn{width: 60px;height: 55px;position: relative;padding: 0;background-color: #f0f3f8;display: inline-block;font-weight: 400;color: #212529;text-align: center;vertical-align: middle;user-select: none;font-size: 14px;line-height: 1.5;margin: 0 5px;padding-top: 5px;} .favorite-num{background: #f00; position: absolute;font-size: 12px;font-weight: 300;top: -5px;right: -5px;padding: 0px 6px;color: #fff;text-shadow: none;border-width: 0;border-style: solid;border-radius: 12px;box-shadow: none;} </style> <div class="favorite-box"> <a href="javascript:;" class="favorite-btn" data-catid="{$catid}" data-id={$id}> <i class="iconfont icon-collection"></i> <span>收藏</span> <small class="favorite-num">{$favorite|default=0}</small> </a> </div> <script> $(function() { //收藏 $(document).on("click", ".favorite-btn", function () { var that = this; $.ajax({ url: "{:url('index/favorite/post')}", type: 'get', dataType: 'json', data: {catid: $(that).data("catid"),id: $(that).data("id")}, success(data){ if(data.code==1){ $('.favorite-num').text(data.data.num); alert(data.msg); }else{ alert(data.msg); } } }); return false; }); }); </script> ``` #### 2.必须对需要的模型增加favorite字段,如文章模型需要用到收藏,则对文章模型增加字段如下 ![](https://img.kancloud.cn/60/30/6030505cbb0c8530f585beae1b30faea_847x674.png)