时间:2021-07-01 10:21:17 帮助过:41人阅读
<td class="center"> {{if $logs[data].flag}}
<a href="JavaScript:void(0);" onclick="istop('{{$logs[data].id}}',0)">取消置顶</a>{{else}} <a href="javascript:void(0);"
onclick="istop('{{$logs[data].id}}',1)">置顶</a>{{/if}}</td>就是用flag判断是否置顶了。
页面对应的置顶js:
function istop(id,flag){
$.ajax({
type: "POST",
url: "?m={{'article'|encrypt}}&a=savePost",
data: "id="+id+"&flag="+flag,
dataType:"json",
success: function(msg){
if(msg.status == "true")
{
window.location= '?m={{'article'|encrypt}}';
}
else
{
alert(msg.message);
}
}
});
}
第三步,程序里只要稍作修改即可。先按是否置顶排序,再按置顶时间排序,再按默认的排序。
$sql .=" ORDER BY flag DESC,top DESC,id DESC ";
(还记得我们添加的字段吗?)
这样就完成了文章置顶的功能。
以上就是php实现文章置顶功能的方法介绍的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!