{"id":29886,"date":"2024-11-25T15:29:02","date_gmt":"2024-11-25T07:29:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29886\/"},"modified":"2024-11-25T15:29:02","modified_gmt":"2024-11-25T07:29:02","slug":"%e7%bb%8f%e5%85%b8%e5%b8%9d%e5%9b%bdcms%e7%94%9f%e6%88%90sitemap%e5%ae%9e%e7%8e%b0%e4%bb%a3%e7%a0%81%e5%88%86%e4%ba%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29886\/","title":{"rendered":"\u7ecf\u5178\u5e1d\u56fdCMS\u751f\u6210sitemap\u5b9e\u73b0\u4ee3\u7801\u5206\u4eab"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/033\/5de0b0ed37b94690.gif\" class=\"aligncenter\" title=\"\u7ecf\u5178\u5e1d\u56fdCMS\u751f\u6210sitemap\u5b9e\u73b0\u4ee3\u7801\u5206\u4eab\u63d2\u56fe\" alt=\"\u7ecf\u5178\u5e1d\u56fdCMS\u751f\u6210sitemap\u5b9e\u73b0\u4ee3\u7801\u5206\u4eab\u63d2\u56fe\" \/><\/p>\n<p>\u56e0\u4e3a\u5bf9\u7684sitemap\u63d2\u4ef6\u4e0d\u592a\u6ee1\u610f\uff0c\u6240\u4ee5\u81ea\u5df1\u5199\u4e86\u4e2asitemap\u751f\u6210\u5de5\u5177\uff0c\u5728sitemap\u4e2d\u653e\u4e86\u9996\u9875\u94fe\u63a5\u3001\u680f\u76ee\u9875\u94fe\u63a5\u548c\u5185\u5bb9\u9875\u94fe\u63a5\uff0c\u7136\u540e\u751f\u6210xml\u6587\u4ef6\u5e76\u4e14\u63d0\u4ea4\u5230\u767e\u5ea6\u7ad9\u957f\u5de5\u5177\uff0c\u672c\u6587\u4e2d\u7684\u4ee3\u7801\u662f\u9700\u8981\u751f\u52a8\u751f\u6210\u7684\uff0c\u6211\u81ea\u5df1\u662f\u5728linux\u4e2d\u7528cron\u5199\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u5929\u56fa\u5b9a\u65f6\u95f4\u751f\u6210\u4e00\u6b21\uff0c\u5148\u8fd9\u6837\u5427~<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre>&lt;?php \/*\u5f15\u7528\u6587\u4ef6*\/\nrequire(&#039;e\/class\/connect.php&#039;);\nrequire(&#039;e\/class\/db_sql.php&#039;);\nrequire(&#039;e\/data\/dbcache\/class.php&#039;);&lt;\/p&gt;&nbsp;&lt;p&gt;\/*\u5efa\u7acb\u6570\u636e\u5e93\u94fe\u63a5&nbsp;\u4e0e&nbsp;\u5b9e\u4f8b\u5316\u7c7b*\/\n$link&nbsp;=&nbsp;db_connect();\n$empire=new&nbsp;mysqlquery();&nbsp;&lt;\/p&gt;&nbsp;&lt;p&gt;\/\/header(\"Content-type:application\/xml\");\nheader(\"Content-type:&nbsp;text\/html;&nbsp;charset=utf-8\");&lt;\/p&gt;&nbsp;&lt;p&gt;$operation&nbsp;=&nbsp;$_GET['operation'];\n$current_url&nbsp;=&nbsp;explode('\/',$_SERVER['PHP_SELF']);\n$current_script_name&nbsp;=&nbsp;end($current_url);&nbsp;&lt;\/p&gt;&nbsp;&lt;p&gt;if($operation&nbsp;&amp;amp;&amp;amp;&nbsp;$operation&nbsp;==&nbsp;\"makexml\")\n{\n$xml&nbsp;=&nbsp;generate_sitemp_xml();\n$result&nbsp;=&nbsp;save_xml('sitemap.xml',$xml);\nif($result)\n{\necho&nbsp;'\u751f\u6210\u6210\u529f\uff0c&lt;a&gt;\u70b9\u6b64\u67e5\u770b&lt;\/a&gt;';\n}\nelse\n{\necho&nbsp;'\u751f\u6210\u5931\u8d25\uff0c&lt;a&gt;\u5728\u6765\u4e00\u6b21&lt;\/a&gt;\uff01';\n}\n}\nelse\n{\necho&nbsp;'\u6b22\u8fce\u4f7f\u7528\u5fae\u7b11\u7684\u9c7cSitemap\u751f\u6210\u5de5\u5177\uff0c\u8bf7&lt;a&gt;\u70b9\u6b64\u751f\u6210&lt;\/a&gt;\uff01';\n}&lt;\/p&gt;&nbsp;&lt;p&gt;&lt;\/p&gt;&nbsp;&lt;p&gt;\n\/\/\u4fdd\u5b58\u5230\u6587\u4ef6\nfunction&nbsp;save_xml($filename,&nbsp;$text)&nbsp;{\nif&nbsp;(!$filename&nbsp;||&nbsp;!$text)\nreturn&nbsp;false;\n\n@chmod($filename,0777);\nif&nbsp;($fp&nbsp;=&nbsp;fopen($filename,&nbsp;\"w\"))&nbsp;{\nif&nbsp;(@fwrite($fp,&nbsp;$text))&nbsp;{\nfclose($fp);\nreturn&nbsp;true;\n}&nbsp;else&nbsp;{\nfclose($fp);\nreturn&nbsp;false;\n}\n}\nreturn&nbsp;false;\n}\n\/\/\u751f\u6210Sitemap&nbsp;XML\u6570\u636e\nfunction&nbsp;generate_sitemp_xml()\n{\nglobal&nbsp;$dbtbpre,$empire;\n\n$xml&nbsp;=&nbsp;'';\n$xml&nbsp;.=&nbsp;'&lt;?xml  version=\"1.0\" encoding=\"utf-8\"?&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&lt;urlset&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;generate_home_xml();\/\/\u9996\u9875\n$xml&nbsp;.=&nbsp;generate_class_xml();\/\/\u680f\u76ee\n\n$query=\"select&nbsp;*&nbsp;from&nbsp;{$dbtbpre}ecms_news&nbsp;order&nbsp;by&nbsp;id&nbsp;desc&nbsp;limit&nbsp;100\";\n$sql=$empire-&amp;gt;query($query);\nwhile($r=$empire-&amp;gt;fetch($sql))\n{\n$titleurl=sys_ReturnBqTitleLink($r);\n\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;url&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;loc&gt;'.$titleurl.'&lt;\/loc&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;lastmod&gt;'.strftime('%Y-%m-%d',$r['newstime']).'&lt;\/lastmod&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;changefreq&gt;daily&lt;\/changefreq&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;priority&gt;0.8&lt;\/priority&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;\/url&gt;'&nbsp;.PHP_EOL;\n\n}\n$xml&nbsp;.=&nbsp;'&lt;\/urlset&gt;'&nbsp;.PHP_EOL;\n\nreturn&nbsp;$xml;\n}\n\/\/\u751f\u6210\u680f\u76ee\u94fe\u63a5XML\u6570\u636e\nfunction&nbsp;generate_class_xml()\n{\nglobal&nbsp;$dbtbpre,$empire,$class_r;\n$xml&nbsp;=&nbsp;'';\n\n$sql=$empire-&amp;gt;query(\"SELECT&nbsp;*&nbsp;FROM&nbsp;{$dbtbpre}enewsclass&nbsp;WHERE&nbsp;islast=1\");\nwhile($r=$empire-&amp;gt;fetch($sql))\n{\n$infor=$empire-&amp;gt;fetch1(\"SELECT&nbsp;newstime&nbsp;FROM&nbsp;{$dbtbpre}ecms_\".$class_r[$r[classid]][tbname].\"&nbsp;WHERE&nbsp;\nclassid='$r[classid]'&nbsp;ORDER&nbsp;BY&nbsp;newstime&nbsp;DESC&nbsp;LIMIT&nbsp;1\");\n$class_url=sys_ReturnBqClassname($r,&nbsp;9);\n\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;url&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;loc&gt;'.$class_url.'&lt;\/loc&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;lastmod&gt;'.strftime('%Y-%m-%d',time()).'&lt;\/lastmod&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;changefreq&gt;daily&lt;\/changefreq&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;priority&gt;0.8&lt;\/priority&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;\/url&gt;'&nbsp;.PHP_EOL;\n\n}\n\nreturn&nbsp;$xml;\n}\n\/\/\u751f\u6210\u680f\u76ee\u94fe\u63a5XML\u6570\u636e\nfunction&nbsp;generate_home_xml()\n{\n$xml&nbsp;=&nbsp;'';\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;url&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;loc&gt;https:\/\/www.jb51.net&lt;\/loc&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;lastmod&gt;'.strftime('%Y-%m-%d',time()).'&lt;\/lastmod&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;changefreq&gt;daily&lt;\/changefreq&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;priority&gt;0.8&lt;\/priority&gt;'&nbsp;.PHP_EOL;\n$xml&nbsp;.=&nbsp;'&nbsp;&lt;\/url&gt;'&nbsp;.PHP_EOL;\n\nreturn&nbsp;$xml;&lt;\/p&gt;&nbsp;&lt;p&gt;}&lt;\/p&gt;&nbsp;&lt;p&gt;\/*\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5&nbsp;\u4e0e&nbsp;\u91ca\u653e\u7c7b*\/\ndb_close();\n$empire=null;\n?&lt;\/p&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u63a8\u8350\u5b66\u4e60\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7ecf\u5178\u5e1d\u56fdCMS\u751f\u6210sitemap\u5b9e\u73b0\u4ee3\u7801\u5206\u4eab\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u5bf9\u7684sitemap\u63d2\u4ef6\u4e0d\u592a\u6ee1\u610f\uff0c\u6240\u4ee5\u81ea\u5df1\u5199\u4e86\u4e2asitemap\u751f\u6210\u5de5\u5177\uff0c\u5728sitemap\u4e2d\u653e\u4e86\u9996\u9875\u94fe\u63a5\u3001\u680f\u76ee\u9875\u94fe\u63a5\u548c\u5185\u5bb9\u9875\u94fe\u63a5\uff0c\u7136\u540e\u751f\u6210xml\u6587\u4ef6\u5e76\u4e14\u63d0\u4ea4\u5230\u767e\u5ea6\u7ad9\u957f\u5de5\u5177\uff0c\u672c\u6587\u4e2d\u7684\u4ee3\u7801\u662f\u9700\u8981\u751f\u52a8\u751f\u6210\u7684\uff0c\u6211\u81ea\u5df1\u662f\u5728linux\u4e2d\u7528cron\u5199\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u5929\u56fa\u5b9a\u65f6\u95f4\u751f\u6210\u4e00\u6b21\uff0c\u5148\u8fd9\u6837\u5427~ \u4ee3\u7801\u5982\u4e0b: &lt;?php \/*\u5f15\u7528\u6587\u4ef6*\/ require(&#039;e\/class\/connect.php&#039;); require(&#039;e\/class\/db_sql.php&#039;); require(&#039;e\/data\/dbcache\/class.php&#039;);&lt;\/p&gt;&nbsp;&lt;p&gt;\/*\u5efa\u7acb\u6570\u636e\u5e93\u94fe\u63a5&nbsp;\u4e0e&nbsp;\u5b9e\u4f8b\u5316\u7c7b*\/ $link&nbsp;=&nbsp;db_connect(); $empire=new&nbsp;mysqlquery();&nbsp;&lt;\/p&gt;&nbsp;&lt;p&gt;\/\/header(&#8220;Content-type:application\/xml&#8221;); header(&#8220;Content-type:&nbsp;text\/html;&nbsp;charset=utf-8&#8221;);&lt;\/p&gt;&nbsp;&lt;p&gt;$operation&nbsp;=&nbsp;$_GET[&#8216;operation&#8217;]; $current_url&nbsp;=&nbsp;explode(&#8216;\/&#8217;,$_SERVER[&#8216;PHP_SELF&#8217;]); $current_script_name&nbsp;=&nbsp;end($current_url);&nbsp;&lt;\/p&gt;&nbsp;&lt;p&gt;if($operation&nbsp;&amp;amp;&amp;amp;&nbsp;$operation&nbsp;==&nbsp;&#8220;makexml&#8221;) { $xml&nbsp;=&nbsp;generate_sitemp_xml(); $result&nbsp;=&nbsp;save_xml(&#8216;sitemap.xml&#8217;,$xml); if($result) { echo&nbsp;&#8216;\u751f\u6210\u6210\u529f\uff0c&lt;a&gt;\u70b9\u6b64\u67e5\u770b&lt;\/a&gt;&#8217;; } else { echo&nbsp;&#8216;\u751f\u6210\u5931\u8d25\uff0c&lt;a&gt;\u5728\u6765\u4e00\u6b21&lt;\/a&gt;\uff01&#8217;; } } else { echo&nbsp;&#8216;\u6b22\u8fce\u4f7f\u7528\u5fae\u7b11\u7684\u9c7cSitemap\u751f\u6210\u5de5\u5177\uff0c\u8bf7&lt;a&gt;\u70b9\u6b64\u751f\u6210&lt;\/a&gt;\uff01&#8217;; }&lt;\/p&gt;&nbsp;&lt;p&gt;&lt;\/p&gt;&nbsp;&lt;p&gt; \/\/\u4fdd\u5b58\u5230\u6587\u4ef6 function&nbsp;save_xml($filename,&nbsp;$text)&nbsp;{ if&nbsp;(!$filename&nbsp;||&nbsp;!$text) return&nbsp;false; @chmod($filename,0777); if&nbsp;($fp&nbsp;=&nbsp;fopen($filename,&nbsp;&#8220;w&#8221;))&nbsp;{ if&nbsp;(@fwrite($fp,&nbsp;$text))&nbsp;{ fclose($fp); return&nbsp;true; }&nbsp;else&nbsp;{ fclose($fp); return&nbsp;false; } } return&nbsp;false; } \/\/\u751f\u6210Sitemap&nbsp;XML\u6570\u636e function&nbsp;generate_sitemp_xml() { global&nbsp;$dbtbpre,$empire; $xml&nbsp;=&nbsp;&#8221;; $xml&nbsp;.=&nbsp;&#8216;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;&#8217;&nbsp;.PHP_EOL; $xml&nbsp;.=&nbsp;&#8216;&lt;urlset&gt;&#8217;&nbsp;.PHP_EOL; $xml&nbsp;.=&nbsp;generate_home_xml();\/\/\u9996\u9875 $xml&nbsp;.=&nbsp;generate_class_xml();\/\/\u680f\u76ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-29886","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29886"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29886\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}