给网站添加分类信息的实现代码
php部分
// 生成分类信息链接 // $flurl 基础链接 url // $uinfo 参数数组 array // $name 当前参数名 string // $value 当前参数值 string function cateinfo($flurl, $uinfo, $name, $value='') { $uinfo[$name] = $value; if (!empty($uinfo)) { $abc = []; foreach ($uinfo as $key => $value) { if ($value) { $abc[] = $key.'='.$value; } } $ustr = implode('&', $abc); } $and = strpos($flurl, '?') === false ? '?' : '&'; $url = $flurl; $url .= $ustr ? $and . $ustr : ''; return $url; } $tid = getRequest('tid'); $name = getRequest('name'); $sort = getRequest('sort');//id tid name taxis $adesc = getRequest('adesc', 'ASC'); // 数据库操作子句 $clause = ''; $clause .= $tid ? " AND tid='$tid'" : ''; $clause .= $sort ? " ORDER BY $sort $adesc " : ''; $gouwuches = $Gouwuche_Model->getList($clause); $flurl = QMHOST . '?plugin=gouwuche&action=index'; $uinfo['tid'] = $tid; $uinfo['sort'] = $sort; $uinfo['adesc'] = $adesc == 'ASC' ? 'DESC' : 'ASC';
html部分
<div class="mgb c"> <a href="<?php echo cateinfo($flurl, $uinfo, 'tid','') ?>" class="btn btn-sm <?php echo $tid == '' ? 'btn-success' : 'btn-info' ?>">全部</a> <?php foreach ($types as $key => $val) { ?> <a href="<?php echo cateinfo($flurl, $uinfo, 'tid', $key) ?>" class="btn btn-sm <?php echo $tid == $key ? 'btn-success' : 'btn-info' ?>"><?php echo $val; ?></a> <?php } ?> </div> <th><a href="<?php echo cateinfo($flurl, $uinfo, 'sort','id') ?>">商品ID</a></th> <th><a href="<?php echo cateinfo($flurl, $uinfo, 'sort','taxis') ?>">排序</a></th> <th><a href="<?php echo cateinfo($flurl, $uinfo, 'sort','tid') ?>">类型</a></th> <th><a href="<?php echo cateinfo($flurl, $uinfo, 'sort','name') ?>">商品</a></th>
代码只做记录,知道其运行逻辑就行
发表评论