What I will show you this time is how to add the like function on the homepage list page of Empire CMS. The Empire CMS template is very easy to use. If you want to add some functions you need based on the template, how should you implement it? This article will give you a good analysis.
Check the content page template code of the news system of the empire cms website building program and find the HTML code block for the likes, as shown below:
<table border="0" align="center" cellpadding="0" cellspacing="0" class="digg"> <tr> <td class="diggnum" id="diggnum"><strong><script type="text/javascript" src="[!--news.url--]e/public/ViewClick/?classid=[!--classid--]&id=[!--id--]&down=5"></script></strong></td> </tr> <tr> <td class="diggit"><a href="JavaScript:makeRequest('[!--news.url--]e/public/digg/?classid=[!--classid--]&id=[!--id--]&dotop=1&doajax=1&ajaxarea=diggnum','EchoReturnedText','GET','');" rel="external nofollow" >来顶一下</a></td> </tr> </table>
It can be seen from the above code that the current total number of likes is passed The dynamic script loading method produces real-time output, and the makeRequest() function on the a tag is used to implement the like function. The first parameter of the makeRequest() function is the request address and accompanied by parameter data. The second parameter is the callback functionname executed after a successful request. The third parameter specifies sending the request in GET mode. After understanding the implementation principle, it is easy to implement the like (like) function on other pages of the website. The relevant code for the implementation method is given below.
For example, if we need to implement the like function on the product list template page, we first need to modify the code of the product list template. The following is my modified list template code:
List content template (list.var)
$nomar=""; if($no%4==0){$nomar=" class=\"nomar\"";}else{$nomar="";} if($r[titlepic]){$tpic=sys_ResizeImg($r[titlepic],300,300,1,"");}else{$tpic="/e/data/images/notimg.gif";} $listtemp='<li'.$nomar.'><p class="photo"><img src="'.$tpic.'"><a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><p class="txt"><h3>查看<br>详情</h3></p></a></p> <b><a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" >[!--title--]([!--model--])</a></b> <a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="icon-thumbs-up" data-classid="[!--classid--]" data-id="[!--id--]"><em>[!--diggtop--]</em>人赞过</a></li>'; 最后在底部模板里或JS文件中加入以下js代码,大功告成 [html] view plain copy print? <script type="text/javascript"> $(".icon-thumbs-up").click(function(event){ event.preventDefault(); var mythis = $(this); var classid = mythis.data("classid"); var id = mythis.data("id"); $.ajax({ type:"GET", url:"[!--news.url--]e/public/digg/", data:{"classid":classid,"id":id,"dotop":1,"doajax":1,"ajaxarea":"diggnum"}, dataType:"text", success:function(data){ var reinfo = data.split("|"); if (reinfo.length != 1) { if (reinfo[0] != "") { mythis.find("em").html(reinfo[0]); } if (reinfo[2] != "") { //var left = parseInt(mythis.offset().left)+20, top = parseInt(mythis.offset().top); var left = 20, top = mythis.find("em").get(0).offsetHeight; $(".zan").remove(); if (reinfo[2] == "谢谢您的支持") { mythis.append('<p class="zan">+1 谢谢您的支持</p>'); //$("body").append('<p class="zan">+1 谢谢您的支持</p>'); }else{ mythis.append('<p class="zan">已赞</p>'); //$("body").append('<p class="zan">已赞</p>'); } //"text-shadow":"0 1px 0 rgba(0,0,0,0.5)","font-family":"simsun" $(".zan").css({"position":"absolute","z-index":"10","left":left+"px","top":-top+"px","color":"inherit"}).animate({top:-top-30},"slow",function(){$(this).fadeIn("fast").remove();}); } }else{} } }); }); </script>
I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to use vue to implement login verification
js to achieve the imitation window system calendar effect
How can JS click to jump to the logged-in personal mailbox
The above is the detailed content of How to add the like function to the homepage list page of Empire CMS. For more information, please follow other related articles on the PHP Chinese website!