步骤:
1、根目录下新增文件readid.php
<?php
header("Cache-Control: no-cache, must-revalidate");
require dirname(__FILE__).'/include/common.inc.php';
$contentid = isset($contentid) ? intval($contentid) : 0;
$readid = get_cookie('readid');
if(intval($readid))$readwhere = $readid;
switch($action)
{
case 'read':
if($contentid){
if(intval($readid))
{
$readid = $contentid.','.$readid;
$tmp = explode(",",$readid);
$tmp = array_unique($tmp);
while(count($tmp) > 10)array_pop($tmp);
$readid = implode(",",$tmp);
}
else $readid = $contentid;
set_cookie('readid',$readid,time()+3600*365*24);
}
break;
case 'list':
include template($mod, 'read_fang');
break;
}
?>
2. New template file read_fang.html
<ul>
{if $readwhere}
{get sql="SELECT * FROM `phpcms_content` WHERE contentid IN ($readwhere) AND status = '99' ORDER BY FIND_IN_SET(contentid,'$readwhere')" rows="10"}
<li><a href="{$r[url]}" title="{$r['title']}">{$r['title']}</a></li>
{/get}
{else}
<li>您还没有浏览过任何记录</li>
{/if}
</ul>
3. Static page call:
(1) The content page template file that needs to be called, such as show.html, plus:
<script language="JavaScript" src="readid.php?contentid={$contentid}&action=read" ></script>
(2) Calling the browsing page:
first add JS code:
<script type="text/javascript">
$(document).ready(function(){
$('#readhouse').load(" readid.php?action=list");
});
</script>
In the place where you need to display the browsing history, add:
<div id="readhouse"><img src="images/loading.gif" align="absmiddle"> Loading data</div>