个人接触XF2的时间不是很久,所以还有很多需要改进的地方(尤其是在数据库方便,我一直都是单独写的,需要继续研究)。
有什么好的建议或者意见可以提出来,喷出来也行,谢谢大家帮我成长。
效果图:
从数据库提取相关数据:
$thread_id = $_POST['thread_id'] ;
$connect = @mysqli_connect('','','');
//连接数据库
if(!$connect){
echo '数据库连接失败'.mysqli_error($connect);
}
mysqli_select_db( $connect, '' );
$result = mysqli_query($connect,"select first_post_likes from xf_thread where thread_id=$thread_id") or die(mysqli_error($connect));
while($tr=mysqli_fetch_row($result)){
$zan = $tr[0];
}
print_r($zan);
前端显示:
thread_list_macros中搜索<div class="structItem-cell structItem-cell--main,在其下添加
<ul class="dianzanshu">
<div style="display:none;" id="{$thread.thread_id}">{$thread.thread_id}</div>
<div>
<div id="zan-{$thread.thread_id}" class="zan"></div>
<script src="/js/vendor/jquery/jquery-3.2.1.min.js"></script>
<script>
var thread_id = $('#{$thread.thread_id}').html();
$.post('/custom/zan.php',{'thread_id':thread_id}, function (s) {
if(s != 0){
$("#zan-{$thread.thread_id}").append('<i class="fa fa-thumbs-up zan-tubiao" aria-hidden="true"></i><div class="zan-x">x</div><div class="zan-num" id="num-{$thread.thread_id}">'+s+'</div>');
}else{
$("#zan-{$thread.thread_id}").append('<div style="visibility:hidden;"><i class="fa fa-thumbs-up zan-tubiao" aria-hidden="true"></i><div class="zan-x">x</div><div class="zan-num" id="num-{$thread.thread_id}">'+s+'</div></div>');
}
})
</script>
</div>
</ul>
CSS样式
extra.less
.zan{
margin: 0 auto;
}
.zan-tubiao{
float: left;color: #EEA9B8;line-height: inherit;
}
.zan-x{
float: left;font-size: 11px;color: #8c8c8c;padding: 4px;
}
.zan-num{
color: #EEA9B8;float:left;
}
.dianzanshu{padding: 0 5%;float: right;}