【XenForo】為Forum列表中最新的貼子加上NEW標記
阿新 • • 發佈:2018-12-18
PHP:
<?php //連線資料庫 $connect = @mysqli_connect('','',''); if(!$connect){ echo '資料庫連線失敗'.mysqli_error($connect); } mysqli_select_db( $connect, 'hairloss' ); $result = mysqli_query($connect, "select post_id,thread_id from xf_post where thread_id in( select thread_id from (select thread_id from xf_thread ORDER BY last_post_date desc LIMIT 5 ) as top_five_thread_ids ) ORDER BY post_id desc;" ) or die(mysqli_error($connect)); $newMembers = []; $i=0; while($tr=mysqli_fetch_row($result)){ $newMembers[$i++] = $tr[0]; } print_r(json_encode($newMembers));
node_list_forum:
<div class="{$extras.last_post_id}"></div> <a href="{{ link('posts', {'post_id': $extras.last_post_id}) }}" class="node-extra-title" title="{$extras.last_thread_title}">{$extras.last_thread_title}</a></div> <div class="node-extra-row"> <div style="display:none;" id="{$extras.last_post_id}">{$extras.last_post_id}</div> <script src="/js/vendor/jquery/jquery-3.2.1.min.js"></script> <script> $.get('/custom/latest_posts.php', function (s) { var latestpostsids = JSON.parse(s); var post_id = $('#{$extras.last_post_id}').html(); for(var i=0;i<latestpostsids.length;i++){ if(latestpostsids[i]== post_id){ $(".{$extras.last_post_id}").append('<div class="new">NEW</div>'); } } }) </script>
最終效果圖: