通過(guò)服務(wù)器的定時(shí)任務(wù)自動(dòng)更新網(wǎng)站全站的所有文章,并生成sitemaps
以下代碼為sitemaps crontab for phpcms v9,以下代碼保存到phpcms 根目錄下,配置cronTab定時(shí)生成即可
代碼:
PHP Code復(fù)制內(nèi)容到剪貼板
- <?php
- /**
- * sitemap.php PHPCMS V9 sitemaps入口
- *
- * @copyright (C) 2015-2018 piaoyun.cc
- * @license http://piaoyun.cc
- * @lastmodify 2015-05-06
- */
- if(PHP_SAPI != 'cli')
- {
- header('location: sitemaps.xml');
- exit;
- }
- define('SITEMAP_SIZE', 10000); //sitemaps中最大輸出數(shù)量
- define('MODEL_SIZE', 3000); //每個(gè)模型中最大輸出數(shù)量
- $model_arr = array(1=>'資訊', 2=>'圖片', 3=>'下載'); //定義需要生成sitemaps的模型
- define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
- include PHPCMS_PATH.'/phpcms/base.php';
- $param = pc_base::load_sys_class('param');
- $model_arr = emptyempty($model_arr) ? getcache('model','commons') : $model_arr;
- $map = array();
- foreach ($model_arr as $modelid => $model)
- {
- $tablename = $model['tablename'];
- $db = pc_base::load_model('content_model');
- $db->set_model($modelid);
- if($db->count() && count($map) < SITEMAP_SIZE)
- {
- $order = 'id desc';
- $arc = $db->select(array('status'=>99), 'url,updatetime', MODEL_SIZE, $order);
- $map = array_merge($map, $arc);
- }
- }
- /* 遍歷生成 */
- $html = '<?xml version="1.0" encoding="utf-8"?>
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
- foreach ($map as $row)
- {
- if(emptyempty($row) || emptyempty($row['url'])) continue;
- $date = date("Y-m-d", $row['updatetime']);
- $url = str_replace(array('&', '\'', '"', '>', '<'), array('&', ''', '"', '>', '<'), $row['url']);
- $html .= "
- <url>
- <loc>{$url}</loc>
- <lastmod>{$date}</lastmod>
- <changefreq>daily</changefreq>
- <priority>0.8</priority>
- </url>";
- }
- $html .= '</urlset>';
- file_put_contents('./sitemaps.xml', $html);
- ?>
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。