这篇文章主要为大家详细介绍了织梦CMS实现首页定时自定生成并且调用随机文章的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。
可能到文章标题“织梦CMS实现首页定时自定生成并且调用随机文章的实现方法”,大家都觉得很高大上吧。其实这样的功能,很早之前都有了,这里只不过是织梦361将两个功能加到了一起,方便网站的SEO。
首先我们来说下织梦模板首页自动生成
我们只需要复制下面代码,粘贴到一个新文件中,命名为:autoindex.php,上传到网站根目录的plus文件夹中。<?php
function sp_input( $text )
{
$text = trim( $text );
$text = htmlspecialchars( $text );
if (!get_magic_quotes_gpc())
return addslashes( $text );
else
return $text;
}
$autotime = 3600;//自动更新时间,单位为秒,这里我设为一小时,大家可以自行更改。
$fpath = "../data/last_time.inc";//记录更新时间文件,如果不能达到目的,请检查是否有读取权限。
include( $fpath );
if( empty($last_time))
$last_time = 0;
if( sp_input($_GET['renew'])=="now")
$last_time = 0;
if((time()-$last_time)>=$autotime )
{
define('DEDEADMIN', ereg_replace("[/\]{1,}",'/',dirname(__FILE__) ) );
require_once(DEDEADMIN."/../include/common.inc.php");
require_once(DEDEINC."/arc.partview.class.php");
/*
$row = $dsql->GetOne("Select * From dede_homepageset");
$dsql->Close();
$templet=$row['templet'];
$position=$row['position'];
*/
$templet = “ke361/index.htm”;//这里是首页模板位置,当前是ke361默认首面位置。
$position = "../index.html";
$homeFile = dirname(__FILE__)."/".$position;
$homeFile = str_replace("\", "/", $homeFile );
$homeFile = str_replace( "//", "/", $homeFile );
$pv = new PartView();
$pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir."/".$templet );
$pv -> SaveToHtml( $homeFile );
$pv -> Close();
$file = fopen( $fpath, "w");
fwrite( $file, "<?php ");
fwrite( $file,"$last_time=".time()."; ");
fwrite( $file, '?>' );
fclose( $file );
}
?>
然后我们需要在首页的模版代码head标签中引入下面这段代码,也就是引入autoindex.php这个php文件:
完成以上步骤后在后台点击生成-更新首页。这里织梦361模板网小编提醒一下要看清楚上面的注释,时间是以秒为单位的,默认3600秒是一小时,大家可以自行更改。
第二个功能、调用随机文章
这个就更简单的了,在首页模板里的相应位置使用下面的调用代码,或者把你的标签代码里想显示随机的地方,增加一个sort=’rand’。就可以了{dede:arclist sort=’rand’ titlelen=48 row=16}
[field:title/]{/dede:arclist}
综合上面2个部分,我们就实现了标题所说的实现首页定时自定生成并且调用随机文章的设想了,有兴趣的朋友可以自己尝试看看效果。
以上就是织梦CMS实现首页定时自定生成并且调用随机文章的实现方法的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持361模板网。
感谢打赏,我们会为大家提供更多优质资源!
更多推荐
织梦cms 定时生成html,织梦CMS实现首页定时自定生成并且调用随机文章的实现方法...
发布评论