330
PbootCMS生成的sitemap.xml中增加tag标签链接

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

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

01// 指定分类标签调用
02public 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行后面增加

01if (! ! $rs = $this->model->getSortTags('')) {
02    $tags = implode(',', $rs); // 把栏目tags串起来 磊宇云计算
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}


这条帮助是否解决了您的问题? 已解决 未解决

提交成功!非常感谢您的反馈,我们会继续努力做到更好! 很抱歉未能解决您的疑问。我们已收到您的反馈意见,同时会及时作出反馈处理!