一个资源分享、信息整合的综合性站点。

标题: 织梦dedecms模板中显示最近浏览文章的方法 [打印本页]

作者: 树苗收集系    时间: 2019-11-26 23:33
标题: 织梦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. {
  20. echo "document.write(‘".$row['title']."’);\r\n";  
  21. }
  22. }
  23. if(!$mid){
  24. $m = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and ip=’$joinip’");
  25. if(!$m){
  26. $dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
  27. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  28. }
  29. $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");   
  30. $db->Execute();   
  31. while($row = $db->GetArray())   
  32. {
  33. echo "document.write(‘".$row['title']."’);\r\n";  
  34. }
  35. }
  36. exit();
  37. ?>
复制代码
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. {
  20. echo "document.write("<a href=’view.php?aid=".$row['id']."’>");";
  21. echo "document.write(‘".$row['title']."’);";
  22. echo "document.write("</a>");\r\n";  
  23. }
  24. }
  25. if(!$mid){
  26. $m = $dsql->GetOne(" Select * From `dede_zjw`  where aid=’$aid’ and ip=’$joinip’");
  27. if(!$m){
  28. $dsql->ExecuteNoneQuery("INSERT INTO dede_zjw( `id`, `mid`, `ip`,`aid` ,`logintime`)
  29. VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
  30. }
  31. $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");   
  32. $db->Execute();   
  33. while($row = $db->GetArray())   
  34. {
  35. echo "document.write("<a href=’view.php?aid=".$row['id']."’>");";
  36. echo "document.write(‘".$row['title']."’);";
  37. echo "document.write("</a>");\r\n";
  38. }
  39. }
  40. exit();
  41. ?>
复制代码
覆盖上面的count_zj.php文件







欢迎光临 一个资源分享、信息整合的综合性站点。 (https://sorv.cn/) Powered by Discuz! X3.4