织梦侠
WWW.2L3.NET

织梦dedecms模板中显示最近浏览文章列表

我们在制作织梦商城模板的时候经常会仿照shopex或者ecshop模式,在列表dede模板中添加最近浏览文章列表,这样可以提高客户的体验度,下面dedecms模板中心跟大家分享下实现方法:
1.后台出执行如下语句
  1. CREATE TABLE `数据库`.`dede_zj` (
  2.   `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  3.   `mid` INTEGER UNSIGNED NOT NULL,
  4.   `ip` VARCHAR(45) NOT NULL,
  5.   `aid` INTEGER UNSIGNED NOT NULL,
  6.   `logintime` VARCHAR(45) NOT NULL,
  7.   PRIMARY KEY (`id`)
  8. )
2.新建php文件count_zj.php 存放到puls目录下内容如下
  1. <?php
  2. require_once(dirname(__FILE__)."/../include/common.inc.php");
  3. require_once(dirname(__FILE__)."/../member/config.php");
  4. global $cfg_ml;
  5. $mid=$cfg_ml->M_ID;
  6. $joinip = GetIP();
  7. //当前时间戳
  8. $nowTime = time();
  9. if($mid)
  10. {
  11. $row = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and mid=’$mid’");
  12. if(!$row){
  13. $dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
  14. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  15. }
  16. $db->SetQuery(" Select title From dede_archives  join dede_zj on dede_archives.id=dede_zj.aid where dede_zj.mid=’$mid’ order by logintime desc limit 1,5");   
  17. $db->Execute();   
  18. while($row = $db->GetArray())   
  19. echo "document.write(‘".$row['title']."’);\r\n";  
  20. }
  21. if(!$mid){
  22. $m = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and ip=’$joinip’");
  23. if(!$m){
  24. $dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
  25. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  26. }
  27. $db->SetQuery(" Select title From dede_archives  join dede_zj on dede_archives.id=dede_zj.aid where dede_zj.ip=’$joinip’ order by logintime desc limit 1,5");   
  28. $db->Execute();   
  29. while($row = $db->GetArray())   
  30. echo "document.write(‘".$row['title']."’);\r\n";  
  31. }
  32. exit();
  33. ?>
3.在文章模板处添加如下语句
  1. <SPAN id="span_zj"> 
  2. <script src="{dede:field name=’phpurl’/}/count_zj.php?view=yes&aid={dede:field name=’id’/}&mid={dede:field name=’mid’/}" type=’text/javascript’ language="javascript"></script>
  3. <script type="text/javascript">  
  4. document.getElementById("zj").innerHTML = document.getElementById("span_zj").innerHTML; 
  5. document.getElementById("span_zj").innerHTML = ""; 
  6. </script>
  7. </SPAN> 
在引用处直接添加<SPAN id="span_zj"></SPAN>排版本人不在行,功能上是可以实现的,望各位自己酌情处理
补充一点,关于最近浏览链接的问题
  1. <?php
  2. require_once(dirname(__FILE__)."/../include/common.inc.php");
  3. require_once(dirname(__FILE__)."/../member/config.php");
  4. global $cfg_ml;
  5. $mid=$cfg_ml->M_ID;
  6. $joinip = GetIP();
  7. //当前时间戳
  8. $nowTime = time();
  9. if($mid)
  10. {
  11. $row = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and mid=’$mid’");
  12. if(!$row){
  13. $dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
  14. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  15. }
  16. $db->SetQuery(" Select title,dede_archives.id From dede_archives  join dede_zj on dede_archives.id=dede_zj.aid where dede_zj.mid=’$mid’ order by logintime desc limit 1,5");   
  17. $db->Execute();   
  18. while($row = $db->GetArray())   
  19. echo "document.write(\"<a href=’view.php?aid=".$row['id']."’>\");"; 
  20. echo "document.write(‘".$row['title']."’);"; 
  21. echo "document.write(\"</a>\");\r\n";  
  22. }
  23. if(!$mid){
  24. $m = $dsql->GetOne(" Select * From `dede_zjw`  where aid=’$aid’ and ip=’$joinip’");
  25. if(!$m){
  26. $dsql->ExecuteNoneQuery("INSERT INTO dede_zjw( `id`, `mid`, `ip`,`aid` ,`logintime`)
  27. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  28. }
  29. $db->SetQuery(" Select title,dede_archives.id From dede_archives  join dede_zj on dede_archives.id=dede_zj.aid where dede_zjw.ip=’$joinip’ order by logintime desc limit 1,5");   
  30. $db->Execute();   
  31. while($row = $db->GetArray())   
  32. echo "document.write(\"<a href=’view.php?aid=".$row['id']."’>\");"; 
  33. echo "document.write(‘".$row['title']."’);"; 
  34. echo "document.write(\"</a>\");\r\n"; 
  35. }
  36. exit();
  37. ?>
覆盖上面的php文件
转载请注明文章来自织梦侠[秩名]作者的-织梦dedecms模板中显示最近浏览文章列表
联系作者
取消
这个作者很懒什么也没留下!
打赏作者
取消

本文作者无偿奉献,就打赏给我们织梦侠吧!

扫码支付
扫码打赏,建议金额1-10元

打开支付宝扫一扫,即可进行扫码打赏哦

提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。