pbootcms默认生成的sitemap.xml中是不含tag标签链接的,如果我们想要实现在sitemap.xml直接生成tags标签,这个要怎么操作呢?

养好习惯,修改这些文件之前做好备份。
1、打开/apps/home/model/SitemapModel.php,在78行后面增加个指定分类标签调用代码。

01 // 指定分类标签调用
02 public function getSortTags($scode)
03 {
04     $join = array(
05         array(
06             'ay_content_sort b',
07             'a.scode=b.scode',
08             'LEFT'
09         ),
10         array(
11             'ay_model c',
12             'b.mcode=c.mcode',
13             'LEFT'
14         )
15     );
16     
17     $scode_arr = array();
18     if ($scode) {
19         // 获取所有子类分类编码
20         $this->scodes = array(); // 先清空
21         $scodes = $this->getSubScodes(trim($scode)); // 获取子类
22                                                      
23         // 拼接条件
24         $scode_arr = array(
25             "a.scode in (" . implode_quot(',', $scodes) . ")",
26             "a.subscode='$scode'"
27         );
28     }
29     $result = parent::table('ay_content a')->where('a.status=1')->where("c.type=2 AND a.tags<>''")
30         ->where($scode_arr, 'OR')
31         ->join($join)
32         ->order('a.visits DESC')
33         ->column('a.tags');
34     return $result;
35 }

2、打开/apps/home/controller/SitemapController.php,在73行后面增加

01 if (! ! $rs = $this->model->getSortTags('')) {
02     $tags = implode(',', $rs); // 把栏目tags串起来 AB模板网
03     $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
04     foreach ($tags as $key2 => $value2) {
05         if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
06             $url_rule_type = $this->config('url_rule_type') ?: 3;
07             if ($url_rule_type == 3) {
08                 $link2 = Url::home('tag=' . urlencode($value2), '');
09             else {
10                 $link2 = Url::home('tag/' . urlencode($value2));
11             }
12             $str .= $this->makeNode($link2, date('Y-m-d'), '0.80');
13         }
14     }
15 }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。