Moke|墨客

 找回密码
 立即注册
搜索
查看: 9421|回复: 0

discuz教程:制作门户的百度sitemap的方法

[复制链接]

3636

主题

0

回帖

3681

积分

超级版主

Rank: 8Rank: 8

积分
3681
发表于 2016-5-9 15:33:01 | 显示全部楼层 |阅读模式



    实现思路:
因为百度sitemap可以提交xml文件,所以我们可以利用discus内置的rss来实现。
实现方法:
1、打开根目录的portal.php   文件
找到
if(empty($_GET['mod']) || !in_array($_GET['mod'], array('list', 'view', 'comment', 'portalcp', 'topic', 'attachment', 'rss', 'block'))) $_GET['mod'] = 'index';
修改为
if(empty($_GET['mod']) || !in_array($_GET['mod'], array('list', 'view', 'comment', 'portalcp', 'topic', 'attachment', 'rss', 'block', 'sitemap'))) $_GET['mod'] = 'index';  
2、找到 source/module/portal/portal_rss.php 文件并复制一份,命名为 portal_sitemap.php
打开 portal_sitemap.php 文件
找到
echo      "<?xml version=\"1.0\" encoding=\"".$charset."\"?>\n".
      "<rss version=\"2.0\">\n".
      "  <channel>\n".
      (count($catarray) > 1 ?
           "    <title>{$_G[setting][bbname]}</title>\n".
           "    <link>{$_G[siteurl]}forum.php</link>\n".
           "    <description>Latest $num articles of all categories</description>\n"
           :
           "    <title>{$_G[setting][bbname]} - $catname</title>\n".
           "    <link>{$_G[siteurl]}portal.php?mod=list&catid=$rsscatid</link>\n".
           "    <description>Latest $num articles of $catname</description>\n"
      ).
      "    <copyright>Copyright(C) {$_G[setting][bbname]}</copyright>\n".
      "    <generator>Discuz! Board by Comsenz Inc.</generator>\n".
      "    <lastBuildDate>".gmdate('r', TIMESTAMP)."</lastBuildDate>\n".
      "    <ttl>$ttl</ttl>\n".
      "    <image>\n".
      "      <url>{$_G[siteurl]}static/image/common/logo_88_31.gif</url>\n".
      "      <title>{$_G[setting][bbname]}</title>\n".
      "      <link>{$_G[siteurl]}</link>\n".
      "    </image>\n";

修改为
echo      "<?xml version=\"1.0\" encoding=\"".$charset."\"?>\n".
      "  <urlset>\n";

找到
echo      "    <item>\n".
                          "      <title>".$article['subject']."</title>\n".
                          "      <link>$_G[siteurl]".($rewriteflag ? rewriteoutput('portal_article', 1, '', $article[aid]) : "portal.php?mod=view&aid=$article[aid]")."</link>\n".
                          "      <description><![CDATA[".dhtmlspecialchars($article['description'])."]]></description>\n".
                          "      <category>".dhtmlspecialchars($article['catname'])."</category>\n".
                          "      <author>".dhtmlspecialchars($article['author'])."</author>\n".
                          ($attachfile ? '<enclosure url="'.$filename.'" length="'.$attachsize.'" type="image/jpeg" />'."\n" : '').
                          "      <pubDate>".gmdate('r', $article['dateline'])."</pubDate>\n".
                          "    </item>\n";

修改为
echo      "    <url>\n".
                          "      <loc>$_G[siteurl]".($rewriteflag ? rewriteoutput('portal_article', 1, '', $article[aid]) : "portal.php?mod=view&aid=$article[aid]")."</loc>\n".
                          "      <lastmod>".date('Y-m-d', $article['dateline'])."</lastmod>\n".
                                         "      <changefreq>daily</changefreq>\n".
                                         "      <priority>1.0</priority>\n".
                          "    </url>\n";

找到
echo      "  </channel>\n".
      "</rss>";

修改为
echo      "  </urlset>\n";
然后访问地址:http://www.moke8.ccom/ portal.php?mod=sitemap即可看到效果,百度sitemap提交这个地址即可。
注意显示条数,可以修改portal_sitemap.php这里:$num = 20;  程序默认是显示20条,可根据自己的需要更改。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 

 

快速回复 返回顶部 返回列表