Home > CMS Tutorial > DEDECMS > body text

How to display the list of recently viewed articles in the dedecms template

藏色散人
Release: 2019-12-10 09:41:42
Original
1950 people have browsed it

How to display the list of recently viewed articles in the dedecms template

How to display the list of recently viewed articles in the dedecms template?

When we make the Dreamweaver Mall template, we often imitate the shopex or ecshop model and add a list of recently browsed articles to the list dede template, which can improve the customer experience. The following dedecms template center follows Let’s share the implementation method:

Recommended learning: 梦Weavercms

1. Execute the following statement in the background

CREATE TABLE `数据库`.`dede_zj` (
  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `mid` INTEGER UNSIGNED NOT NULL,
  `ip` VARCHAR(45) NOT NULL,
  `aid` INTEGER UNSIGNED NOT NULL,
  `logintime` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`)
)
Copy after login

2. Create a new php file count_zj .php is stored in the puls directory and the content is as follows

<?php
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(dirname(__FILE__)."/../member/config.php");
global $cfg_ml;
$mid=$cfg_ml->M_ID;
$joinip = GetIP();
//当前时间戳
$nowTime = time();
if($mid)
{
$row = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and mid=’$mid’");
if(!$row){
$dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
}
$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");   
$db->Execute();   
while($row = $db->GetArray())   
{ 
echo "document.write(‘".$row[&#39;title&#39;]."’);\r\n";  
} 
}
if(!$mid){
$m = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and ip=’$joinip’");
if(!$m){
$dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
}
$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");   
$db->Execute();   
while($row = $db->GetArray())   
{ 
echo "document.write(‘".$row[&#39;title&#39;]."’);\r\n";  
} 
}
exit();
?>
Copy after login

3. Add the following statement to the article template

<SPAN id="span_zj"> 
<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>
<script type="text/javascript">  
document.getElementById("zj").innerHTML = document.getElementById("span_zj").innerHTML; 
document.getElementById("span_zj").innerHTML = ""; 
</script>
</SPAN>
Copy after login

Add I am not good at typesetting, but the function is achievable. I hope you can handle it at your own discretion

Add one point, regarding the issue of recently browsed links

<?php
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(dirname(__FILE__)."/../member/config.php");
global $cfg_ml;
$mid=$cfg_ml->M_ID;
$joinip = GetIP();
//当前时间戳
$nowTime = time();
if($mid)
{
$row = $dsql->GetOne(" Select * From `dede_zj`  where aid=’$aid’ and mid=’$mid’");
if(!$row){
$dsql->ExecuteNoneQuery("INSERT INTO dede_zj( `id`, `mid`, `ip`,`aid` ,`logintime`)
VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
}
$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");   
$db->Execute();   
while($row = $db->GetArray())   
{ 
echo "document.write(\"<a href=’view.php?aid=".$row[&#39;id&#39;]."’>\");"; 
echo "document.write(‘".$row[&#39;title&#39;]."’);"; 
echo "document.write(\"</a>\");\r\n";  
} 
}
if(!$mid){
$m = $dsql->GetOne(" Select * From `dede_zjw`  where aid=’$aid’ and ip=’$joinip’");
if(!$m){
$dsql->ExecuteNoneQuery("INSERT INTO dede_zjw( `id`, `mid`, `ip`,`aid` ,`logintime`)
VALUES (  ”,$mid, ‘$joinip’,$aid,$nowTime) ");
}
$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");   
$db->Execute();   
while($row = $db->GetArray())   
{ 
echo "document.write(\"<a href=’view.php?aid=".$row[&#39;id&#39;]."’>\");"; 
echo "document.write(‘".$row[&#39;title&#39;]."’);"; 
echo "document.write(\"</a>\");\r\n"; 
} 
}
exit();
?>
Copy after login

Overwrite the above php file

The above is the detailed content of How to display the list of recently viewed articles in the dedecms template. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!