可能到文章标题“织梦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文件:
<script src="/plus/autoindex.php" language="javascript"></script>
完成以上步骤后在后台点击生成-更新首页。这里织梦乐享吧网小编提醒一下要看清楚上面的注释,时间是以秒为单位的,默认3600秒是一小时,大家可以自行更改。
第二个功能、调用随机文章
这个就更简单的了,在首页模板里的相应位置使用下面的调用代码,或者把你的标签代码里想显示随机的地方,增加一个sort=’rand’。就可以了
{dede:arclist sort=’rand’ titlelen=48 row=16} <li><a href="[field:arcurl/]" title="[field:title/]" target="_blank">[field:title/]</a></li> {/dede:arclist}
综合上面2个部分,我们就实现了标题所说的实现首页定时自定生成并且调用随机文章的设想了,有兴趣的朋友可以自己尝试看看效果。
以上就是织梦CMS实现首页定时自定生成并且调用随机文章的实现方法的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持乐享吧网。织梦模板制作中添加自定义内容模型前台调用失败怎么解决
提出这个问题是因为昨天给用户做一个织梦模板的时候,在织梦DedeCMS添加自定义内容模型,发现在前台死活就是读不出来数值,都要急疯了。按道理来说这样的事情织梦361做过不知道了