将以下代码保存 放入 dayrui/app/tag/config/Hooks.php (没有就新建一个)
我是通过内容发布之后的钩子来直接修改数据表的 所以需要先安装tag插件 然后 模块配置里开启自动存储关键词
<?php
\Phpcmf\Hooks::on('module_content_after', function($data) {
$table = SITE_ID.'_tag';
$table2 = \Phpcmf\Service::M()->prefix.SITE_ID.'_tag';
$catid = $data['1']['catid'];
$tag = $data['1']['keywords'];
$module = APP_DIR;
if (!\Phpcmf\Service::M()->db->fieldExists('catid', $table2)) {
\Phpcmf\Service::M()->query('ALTER TABLE `'.$table2.'` ADD `catid` INT(10) NOT NULL COMMENT \'栏目id\'');
}
if (!\Phpcmf\Service::M()->db->fieldExists('module', $table2)) {
\Phpcmf\Service::M()->query('ALTER TABLE `'.$table2.'` ADD `module` varchar(200) NOT NULL COMMENT \'模块名称\'');
}
if (!$tag) {
return;
}
$arr = explode(',', $tag);
foreach ($arr as $t) {
if ($t) {
\Phpcmf\Service::M()->db->table($table)->where('name', $t)->update([
'catid' => $catid,'module' => $module]);
}
}
});然后列表显示的话 请修改 dayrui\App\Tag\Views\tag_list.html 保存以下代码
{template "header.html"}
<link href="{THEME_PATH}assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.css" rel="stylesheet" type="text/css" />
<link href="{THEME_PATH}assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css" rel="stylesheet" type="text/css" />
<link href="{THEME_PATH}assets/global/plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css" rel="stylesheet" type="text/css" />
<link href="{THEME_PATH}assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
<script src="{THEME_PATH}assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.finecms.js" type="text/javascript"></script>
<script type="text/javascript">
if (App.isAngularJsApp() === false) {
jQuery(document).ready(function() {
if (jQuery().datepicker) {
$('.date-picker').datepicker({
rtl: App.isRTL(),
orientation: "left",
autoclose: true
});
}
});
}
</script>
<div class="note note-danger">
<p><a href="javascript:dr_update_cache('tag', '');">{dr_lang('更改数据之后需要更新缓存之后才能生效')}</a></p>
</div>
<div class="row table-search-tool">
<form action="{SELF}" method="get">
{dr_form_search_hidden(['pid'=>$pid])}
<div class="col-md-12 col-sm-12">
<label>
<select name="field" class="form-control">
{loop $field $t}
{if $t.ismain}
<option value="{$t.fieldname}" {if $param.field==$t.fieldname}selected{/if}>{$t.name}</option>
{/if}
{/loop}
</select>
</label>
<label><i class="fa fa-caret-right"></i></label>
<label><input type="text" class="form-control" placeholder="" value="{$param['keyword']}" name="keyword" /></label>
</div>
<div class="col-md-12 col-sm-12">
<button type="submit" class="btn green btn-sm onloading" name="submit" > <i class="fa fa-search"></i> {dr_lang('搜索')}</button>
</div>
{if $pid}
<div class="col-md-12 col-sm-12" style="padding-top:2px">
<a class="btn red btn-sm" href="{dr_url('tag/home/add', ['pid'=>$pid])}"> <i class="fa fa-plus"></i> {dr_lang('添加子词')}</a>
</div>
<div class="col-md-12 col-sm-12" style="padding-top:2px">
<a class="btn blue btn-sm" href="{dr_url('tag/home/all_add', ['pid'=>$pid])}"> <i class="fa fa-plus"></i> {dr_lang('批量子词')}</a>
</div>
{/if}
</form>
</div>
<form class="form-horizontal" role="form" id="myform">
{dr_form_hidden()}
<div class="table-scrollable">
<table class="table table-striped table-bordered table-hover table-checkable dataTable">
<thead>
<tr class="heading">
{if $ci->_is_admin_auth('del')}
<th class="myselect">
<label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="group-checkable" data-set=".checkboxes" />
<span></span>
</label>
</th>
{/if}
<th style="text-align:center" width="70" class="{dr_sorting('displayorder')}" name="displayorder">{dr_lang('权重')}</th>
<th width="220" class="{dr_sorting('name')}" name="name">{dr_lang('名称')}</th>
<th width="170" class="{dr_sorting('code')}" name="code">{dr_lang('别名')}</th>
<th width="100" class="{dr_sorting('hits')}" name="hits">{dr_lang('点击量')}</th>
<th width="100" class="{dr_sorting('hits')}" name="hits">{dr_lang('模块')}</th>
<th width="100" class="{dr_sorting('hits')}" name="hits">{dr_lang('栏目')}</th>
{if $chinaz_tag_api}
<th>{dr_lang('排名')}</th>
{/if}
<th>{dr_lang('操作')}</th>
</tr>
</thead>
<tbody>
{loop $list $t}
<?php
$t['url'] = isset($t['myurl']) && $t['myurl'] ? $t['myurl'] : \Phpcmf\Service::L('router')->tag_url($t['pcode']);
$t['total'] = intval(\Phpcmf\Service::L('cache')->get('tag-'.SITE_ID, $t['code'], 'total'));
?>
<tr class="odd gradeX" id="dr_row_{$t.id}">
{if $ci->_is_admin_auth('del') || $ci->_is_admin_auth('edit')}
<td class="myselect">
<label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="checkboxes" name="ids[]" value="{$t.id}" />
<span></span>
</label>
</td>
{/if}
<td style="text-align:center"> <input type="text" onblur="dr_ajax_save(this.value, '{dr_url('tag/home/order_edit', ['id'=>$t.id])}')" value="{$t.displayorder}" class="displayorder form-control input-sm input-inline input-mini"> </td>
<td>{Function_list::title($t.name, $param, $t)}</td>
<td>{$t.code}</td>
<td>{$t.hits}</td>
<td>{$t.module}</td>
<td>{dr_share_cat_value($t.catid, "name")}</td>
{if $chinaz_tag_api}
<td>
{loop $chinaz_tag_api $i $name}
<p style="margin: 0">{$name} <span id="dr_api_{$i}_{$t.id}">...</span></p>
<script>
$(function () {
$.ajax({
type: "GET",
dataType: "json",
url: "{dr_url('zhanzhang/api/tag')}&id={$i}&tag={$t.name}",
success: function (json) {
$('#dr_api_{$i}_{$t.id}').html(json.msg);
},
error: function(HttpRequest, ajaxOptions, thrownError) {
$('#dr_api_{$i}_{$t.id}').attr('style', 'color:red');
$('#dr_api_{$i}_{$t.id}').html('获取异常,请检查错误日志');
}
});
});
</script>
{/loop}
</td>
{/if}
<td>
{if !$pid}
<label><a href="{dr_url('tag/home/index', ['pid'=>$t.id])}" class="btn btn-xs dark"> <i class="fa fa-tag"></i> {dr_lang('子词管理(%s)', $t.total)}</a></label>
{/if}
{if $ci->_is_admin_auth('edit')}
<label><a href="{dr_url('tag/home/edit', ['id'=>$t.id])}" class="btn btn-xs green"> <i class="fa fa-edit"></i> {dr_lang('修改')}</a></label>
{/if}
</td>
</tr>
{/loop}
</tbody>
</table>
</div>
<div class="row fc-list-footer table-checkable ">
<div class="col-md-5 fc-list-select">
{if $ci->_is_admin_auth('del') || $ci->_is_admin_auth('edit')}
<label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="group-checkable" data-set=".checkboxes" />
<span></span>
</label>
<label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/del')}', '{dr_lang('你确定要删除它们吗?')}', 1)" class="btn red btn-sm"> <i class="fa fa-trash"></i> {dr_lang('删除')}</button></label>
{/if}
</div>
<div class="col-md-7 fc-list-page">
{$mypages}
</div>
</div>
</form>
{template "footer.html"}前台调用的话 可以直接 module=模块名称 catid=栏目id (错了 不能直接接 要用where来接)
{php $where=urlencode("(module='article' and catid=".$t.id.")");}
{tag where=$where num=20 order=rand}
<a href="{$t.url}" title="点击量:{$t.hits}">{$t.name}</a>
{/tag}
文档最后更新时间:2020-05-28 15:49:35