织梦列表页,支持顶(赞)和踩的功能,顶过后标红高亮显示
作者:达特 日期:2023-03-08 分类:CMS教程
模板
01 |
<script language= "javascript" type = "text/javascript" > |
02 |
function postDigg(ftype,aid) |
04 |
var taget_obj = document.getElementById( 'diggNum' +aid); |
06 |
var saveid = GetCookie( 'diggid' ); //我所有赞过的文章 id |
10 |
var saveids = saveid. split ( ',' ); |
14 |
for (i=saveids.length-1;i>=0;i--) |
16 |
if (saveids[i]==aid && hasid) continue ; //我顶过 |
18 |
if (saveids[i]==aid && !hasid) hasid = true ; |
19 |
saveid += (saveid== '' ? saveids[i] : ',' +saveids[i]); |
21 |
if (j==20 && hasid) break ; |
22 |
if (j==19 && !hasid) break ; |
26 |
//alert( "您已经顶过该帖,请不要重复顶帖 !" ); |
27 |
//如果点击后,被赞过.则不需要更新统计,直接改变颜色 |
28 |
$( '#digg' +aid).addClass( "icon-heart-on" ); |
31 |
else saveid += ',' +aid; |
32 |
SetCookie( 'diggid' ,saveid,1); |
37 |
SetCookie( 'diggid' ,aid,1); |
40 |
myajax = new DedeAjax(taget_obj, false , false , '' , '' , '' ); |
41 |
var url = "{dede:global.cfg_phpurl/}/digg_ajax_list.php?action=" +ftype+ "&id=" +aid; |
|
1 |
{dede:arclist row= '6' orderby= 'id' titlelen= '100' } |
3 |
<span id = "diggNum[field:id/]" > <a href= "javascript:" class= " text-bbb text-16" onclick= "javascript:postDigg('good',[field:id/])" ><span id = "digg[field:id/]" class= "icon-heart2 " > </span> </a>[field:goodpost/] |
|
css
2 |
background : url (../images/bg-main.png) -22px 5px no-repeat ; |
5 |
background : url (../images/bg-main.png) 2px 4px no-repeat ; |
8 |
background : url (../images/bg-main.png) 2px 4px no-repeat ; |
|
然后在,plus中新建立一个digg_ajax_list.PHP文件,内容为
03 |
require_once (dirname( __FILE__ ). "/../include/common.inc.php" ); |
05 |
$action = isset( $action ) ? trim( $action ) : '' ; |
06 |
$id = empty ( $id )? 0 : intval (preg_replace( "/[^\d]/" , '' , $id )); |
12 |
$maintable = 'archives' ; |
15 |
$dsql ->ExecuteNoneQuery( "Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=" .time(). " where id='$id'" ); |
17 |
else if ( $action == 'bad' ) |
19 |
$dsql ->ExecuteNoneQuery( "Update `$maintable` set scores = scores - {$cfg_caicai_sub},badpost=badpost+1,lastpost=" .time(). " where id='$id'" ); |
22 |
$row = $dsql ->GetOne( "Select goodpost,badpost,scores From `$maintable` where id='$id' " ); |
27 |
if ( $row [ 'goodpost' ]+ $row [ 'badpost' ] == 0) |
29 |
$row [ 'goodper' ] = $row [ 'badper' ] = 0; |
33 |
$row [ 'goodper' ] = number_format( $row [ 'goodpost' ]/( $row [ 'goodpost' ]+ $row [ 'badpost' ]),3)*100; |
34 |
$row [ 'badper' ] = 100- $row [ 'goodper' ]; |
37 |
if ( empty ( $formurl )) $formurl = '' ; |
38 |
if ( $formurl == 'caicai' ) |
40 |
if ( $action == 'good' ) $digg = $row [ 'goodpost' ]; |
41 |
if ( $action == 'bad' ) $digg = $row [ 'badpost' ]; |
45 |
$row [ 'goodper' ] = trim(sprintf( "%4.2f" , $row [ 'goodper' ])); |
46 |
$row [ 'badper' ] = trim(sprintf( "%4.2f" , $row [ 'badper' ])); |
47 |
$digg = '<a class=" text-bbb text-16"href="javascript:" onclick="javascript:postDigg(\'good\',' . $id . ')"><span =id="digg' . $id . '"class="icon-heart-on"> </span> </a>' . $row [ 'goodpost' ]; |
|