麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > CMS > Wordpress > 正文

wordpress無插件生成文章TXT網站地圖的方法

2024-09-07 00:52:20
字體:
來源:轉載
供稿:網友

我們知道網站地址有利于搜索引擎的收錄,wordpress有自帶的xml格式的網站地圖,如果我們也希望生成txt格式的地圖呢?本文我們用純代碼方法來實現.

該方法不需要安裝任何插件,純代碼生成.

  1. <?php 
  2. require('./wp-blog-header.php'); 
  3. header('Content-type: application/txt'); 
  4. header('HTTP/1.1 200 OK'); 
  5. $posts_to_show = 50000; // 限制最大文章數量 
  6. ?> 
  7. <?php 
  8. header("Content-type: text/txt"); 
  9. $myposts = get_posts( "numberposts=" . $posts_to_show ); 
  10. <a href="/tags.php/foreach/" target="_blank">foreach</a>( $myposts as $post ) {  
  11. //Vevb.com 
  12. ?> 
  13. <?php the_permalink(); ?><?php echo "/n"; ?> 
  14. <?php } ?> 

將上述代碼復制保存為php文件,注意使用utf-8格式,然后將其上傳到你的wordpress安裝根目錄上.

注意:將www.admin.com改為你的網站地址。

設置偽靜態

①、Nginx

編輯已存在的Nginx偽靜態規則,新增如下規則后(平滑)重啟nginx即可:

rewrite ^/ping.txt$ /ping.php last;

②、Apache

編輯網站根目錄的 .htaccess,加入如下規則:

RewriteRule ^(ping)/.xml$ $1.php

做好偽靜態規則后,就可以直接訪問sitemap.xml看看效果了.

最后我們輸入http://www.admin.com/ping.txt就可以看到wordpress無插件純代碼生成txt格式網站地圖的效果了,如果需要下載該txt文件,只需要右鍵另存為即可.

WordPress免插件生成完整站點地圖(sitemap.xml)的php代碼:

  1. <?php 
  2. require('./wp-blog-header.php'); 
  3. header("Content-type: text/xml"); 
  4. header('HTTP/1.1 200 OK'); 
  5. $posts_to_show = 1000;  
  6. echo '<?xml version="1.0" encoding="UTF-8"?>'
  7. echo '<urlset xmlns="http://www.sitema<a href="/fw/photo.html" target="_blank">ps</a>.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">' 
  8. ?> 
  9. <!-- generated-on=<?php echo get_lastpostdate('blog'); ?>--> 
  10.   <url> 
  11.       <loc><?php echo get_home_url(); ?></loc> 
  12.       <lastmod><?php $ltime = get_lastpostmodified(GMT);$ltime = gmdate('Y-m-d/TH:i:s+00:00', <a href="/tags.php/strtotime/" target="_blank">strtotime</a>($ltime)); echo $ltime; ?></lastmod> 
  13.       <changefreq>daily</changefreq> 
  14.       <priority>1.0</priority> 
  15.   </url> 
  16. <?php 
  17. /* 文章頁面 */  
  18. header("Content-type: text/xml"); 
  19. $myposts = get_posts( "numberposts=" . $posts_to_show ); 
  20. foreach$myposts as $post ) { ?> 
  21.   <url> 
  22.       <loc><?php the_permalink(); ?></loc> 
  23.       <lastmod><?php the_time('c') ?></lastmod> 
  24.       <changefreq>monthly</changefreq> 
  25.       <priority>0.6</priority> 
  26.   </url> 
  27. <?php } /* 文章循環結束 */ ?>   
  28. <?php 
  29. /* 單頁面 */  
  30. $mypages = get_pages(); 
  31. if(count($mypages) > 0) { 
  32.     foreach($mypages as $page) { ?> 
  33.     <url> 
  34.       <loc><?php echo get_page_link($page->ID); ?></loc> 
  35.       <lastmod><?php echo str_replace(" ","T",get_page($page->ID)->post_modified); ?>+00:00</lastmod> 
  36.       <changefreq>weekly</changefreq> 
  37.       <priority>0.6</priority> 
  38.   </url> 
  39. <?php }} /* 單頁面循環結束 */ ?>  
  40. <?php 
  41. /* 博客分類 */  
  42. $terms = get_terms('category''orderby=name&hide_empty=0' ); 
  43. $count = count($terms); 
  44. if($count > 0){ 
  45. foreach ($terms as $term) { ?> 
  46.     <url> 
  47.       <loc><?php echo get_term_link($term$term->slug); ?></loc> 
  48.       <changefreq>weekly</changefreq> 
  49.       <priority>0.8</priority> 
  50.   </url> 
  51. <?php }} /* 分類循環結束 */?>  
  52. <?php 
  53.  /* 標簽(可選) */ 
  54. $tags = get_terms("post_tag"); 
  55. foreach ( $tags as $key => $tag ) { 
  56.     $link = get_term_link( intval($tag->term_id), "post_tag" ); 
  57.          if ( is_wp_error( $link ) ) 
  58.           return false; 
  59.           $tags$key ]->link = $link
  60. ?> 
  61.  <url> 
  62.       <loc><?php echo $link ?></loc> 
  63.       <changefreq>monthly</changefreq> 
  64.       <priority>0.4</priority> 
  65.   </url> 
  66. <?php  } /* 標簽循環結束 */ ?>  
  67. </urlset> 

wordpress非插件實現xml格式網站地圖.

  1. <?php 
  2. require('./wp-blog-header.php'); 
  3. header("Content-type: text/xml"); 
  4. header('HTTP/1.1 200 OK'); 
  5. $posts_to_show = 1000; // 獲取文章數量 
  6. echo '<?xml version="1.0" encoding="UTF-8"?>'
  7. echo '<urlset xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="external nofollow" >http://www.w3.org/2001/XMLSchema-instance</a>" xmlns="<a href="http://www.sitemaps.org/schemas/sitemap/0.9" rel="external nofollow" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9</a>" 
  8. xsi:schemaLocation="<a href="http://www.sitemaps.org/schemas/sitemap/0.9" rel="external nofollow" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9</a> <a href="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'</a>; 
  9. ?> 
  10. <!-- generated-on=<?php echo get_lastpostdate('blog'); ?>--> 
  11. <url> 
  12. <loc>http://localhost/</loc> 
  13. <lastmod><?php echo get_lastpostdate('blog'); ?></lastmod> 
  14. <changefreq>daily</changefreq> 
  15. <priority>1.0</priority> 
  16. </url> 
  17. <?php 
  18. header("Content-type: text/xml"); 
  19. $myposts = get_posts( "numberposts=" . $posts_to_show ); 
  20. foreach$myposts as $post ) { ?> 
  21. <url> 
  22. <loc><?php the_permalink(); ?></loc> 
  23. <lastmod><?php the_time('c') ?></lastmod> 
  24. <changefreq>monthly</changefreq> 
  25. <priority>0.6</priority> 
  26. </url> 
  27. <?php } // end foreach ?> 
  28. </urlset> 

復制上面代碼為xmlmap.php文件并傳至網站根目錄:

http://localhost/xmlmap.php

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中文字幕在线观看精品 | 欧美日韩在线播放一区 | 妇子乱av一区二区三区 | 免费视频99 | 久久精品99国产国产精 | 国产免费一级淫片 | 免费看搡女人无遮挡的视频 | 97porn| 欧美性生交xxxxx免费观看 | 国产一区二区观看 | 国产一区成人 | 国产一级桃视频播放 | 91热久久免费频精品黑人99 | 免费国产自久久久久三四区久久 | 欧洲精品久久久久69精品 | 香蕉视频网站在线观看 | 欧美高清另类自拍视频在线看 | 亚洲第五色综合网 | 一区二区三区视频在线 | 国产亚洲精品美女久久久 | 亚洲午夜1000理论片aa | 国产精品v片在线观看不卡 成人一区二区三区在线 | 成人性生活视频在线观看 | 日韩视频不卡 | 日本看片一区二区三区高清 | 久久久一区二区三区四区 | 亚洲一区二区三区在线看 | 国产精品18久久久久久久 | 午夜男人免费视频 | 国产羞羞视频在线观看 | 国产一级毛片国产 | 伊人午夜| 在线看一区二区三区 | 久久精品免费国产 | 男女羞羞视频在线免费观看 | av手机免费在线观看 | 黄色网址你懂的 | 青青青在线免费 | 国产91精品一区二区麻豆亚洲 | 欧美成人久久 | 国产一级免费在线视频 |