因為對帝國CMS的sitemap插件不太滿意,所以自己寫了個sitemap生成工具,在sitemap中放了首頁鏈接、欄目頁鏈接和內容頁鏈接,然後生成XML檔案並且提交到百度站長工具,本文中的程式碼是需要生動生成的,我自己是在Linux中用cron寫的定時任務,每天固定時間生成一次,先這樣吧~
程式碼如下:
<?php /*引用文件*/ require('e/class/connect.php'); require('e/class/db_sql.php'); require('e/data/dbcache/class.php');</p> <p>/*建立数据库链接 与 实例化类*/ $link = db_connect(); $empire=new mysqlquery(); </p> <p>//header("Content-type:application/xml"); header("Content-type: text/html; charset=utf-8");</p> <p>$operation = $_GET['operation']; $current_url = explode('/',$_SERVER['PHP_SELF']); $current_script_name = end($current_url); </p> <p>if($operation && $operation == "makexml") { $xml = generate_sitemp_xml(); $result = save_xml('sitemap.xml',$xml); if($result) { echo '生成成功,<a href="sitemap.xml">点此查看</a>'; } else { echo '生成失败,<a href="'.$current_script_name.'">在来一次</a>!'; } } else { echo '欢迎使用微笑的鱼Sitemap生成工具,请<a href="'.$current_script_name.'?operation=makexml">点此生成</a>!'; }</p> <p></p> <p> //保存到文件 function save_xml($filename, $text) { if (!$filename || !$text) return false; @chmod($filename,0777); if ($fp = fopen($filename, "w")) { if (@fwrite($fp, $text)) { fclose($fp); return true; } else { fclose($fp); return false; } } return false; } //生成Sitemap XML数据 function generate_sitemp_xml() { global $dbtbpre,$empire; $xml = ''; $xml .= '<?xml version="1.0" encoding="utf-8"?>' .PHP_EOL; $xml .= '<urlset>' .PHP_EOL; $xml .= generate_home_xml();//首页 $xml .= generate_class_xml();//栏目 $query="select * from {$dbtbpre}ecms_news order by id desc limit 100"; $sql=$empire->query($query); while($r=$empire->fetch($sql)) { $titleurl=sys_ReturnBqTitleLink($r); $xml .= ' <url>' .PHP_EOL; $xml .= ' <loc>'.$titleurl.'</loc>' .PHP_EOL; $xml .= ' <lastmod>'.strftime('%Y-%m-%d',$r['newstime']).'</lastmod>' .PHP_EOL; $xml .= ' <changefreq>daily</changefreq>' .PHP_EOL; $xml .= ' <priority>0.8</priority>' .PHP_EOL; $xml .= ' </url>' .PHP_EOL; } $xml .= '</urlset>' .PHP_EOL; return $xml; } //生成栏目链接XML数据 function generate_class_xml() { global $dbtbpre,$empire,$class_r; $xml = ''; $sql=$empire->query("SELECT * FROM {$dbtbpre}enewsclass WHERE islast=1"); while($r=$empire->fetch($sql)) { $infor=$empire->fetch1("SELECT newstime FROM {$dbtbpre}ecms_".$class_r[$r[classid]][tbname]." WHERE classid='$r[classid]' ORDER BY newstime DESC LIMIT 1"); $class_url=sys_ReturnBqClassname($r, 9); $xml .= ' <url>' .PHP_EOL; $xml .= ' <loc>'.$class_url.'</loc>' .PHP_EOL; $xml .= ' <lastmod>'.strftime('%Y-%m-%d',time()).'</lastmod>' .PHP_EOL; $xml .= ' <changefreq>daily</changefreq>' .PHP_EOL; $xml .= ' <priority>0.8</priority>' .PHP_EOL; $xml .= ' </url>' .PHP_EOL; } return $xml; } //生成栏目链接XML数据 function generate_home_xml() { $xml = ''; $xml .= ' <url>' .PHP_EOL; $xml .= ' <loc>https://www.jb51.net</loc>' .PHP_EOL; $xml .= ' <lastmod>'.strftime('%Y-%m-%d',time()).'</lastmod>' .PHP_EOL; $xml .= ' <changefreq>daily</changefreq>' .PHP_EOL; $xml .= ' <priority>0.8</priority>' .PHP_EOL; $xml .= ' </url>' .PHP_EOL; return $xml;</p> <p>}</p> <p>/*关闭数据库连接 与 释放类*/ db_close(); $empire=null; ?
推薦學習《帝國cms教學》
以上是經典帝國CMS產生sitemap實作程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!
陳述
本文轉載於:www.word666.com。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
3 週前ByDDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前ByDDD
在哪裡可以找到原子中的起重機控制鑰匙卡
3 週前ByDDD
<🎜>:死鐵路 - 如何完成所有挑戰
4 週前ByDDD
Atomfall指南:項目位置,任務指南和技巧
1 個月前ByDDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具