PbootCMS生成的网站地图sitemap.xml中增加tag标签链接

   声明:本站部分内容来自互联网,如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

16

PbootCMS生成的sitemap.xml中默认是不含tag标签链接的,如果想增加怎么办,下来来介绍下如何二开实现。实现后如下图,所有的tag链接都会进去。

二开步骤

1、打开/apps/home/model/SitemapModel.php,在78行后面增加个指定分类标签调用代码。

PHP

// 指定分类标签调用public function getSortTags($scode){
    $join = array(
        array(
            'ay_content_sort b',
            'a.scode=b.scode',
            'LEFT'
        ),
        array(
            'ay_model c',
            'b.mcode=c.mcode',
            'LEFT'
        )
    );
    
    $scode_arr = array();
    if ($scode) {
        // 获取所有子类分类编码
        $this->scodes = array(); // 先清空
        $scodes = $this->getSubScodes(trim($scode)); // 获取子类
                                                     
        // 拼接条件
        $scode_arr = array(
            "a.scode in (" . implode_quot(',', $scodes) . ")",
            "a.subscode='$scode'"
        );
    }
    $result = parent::table('ay_content a')->where('a.status=1')->where("c.type=2 AND a.tags<>''")
        ->where($scode_arr, 'OR')
        ->join($join)
        ->order('a.visits DESC')
        ->column('a.tags');
    return $result;}

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

PHP

if (! ! $rs = $this->model->getSortTags('')) {
    $tags = implode(',', $rs); // 把栏目tags串起来
    $tags = array_unique(explode(',', $tags)); // 再把所有tags组成数组并去重
    foreach ($tags as $key2 => $value2) {
        if (! in_array($value2, array_column($data, 'tags'))) { // 避免重复输出
            $url_rule_type = $this->config('url_rule_type') ?: 3;
            if ($url_rule_type == 3) {
                $link2 = Url::home('tag=' . urlencode($value2), '');
            } else {
                $link2 = Url::home('tag/' . urlencode($value2));
            }
            $str .= $this->makeNode($link2, date('Y-m-d'), '0.80');
        }
    }}

完成以上两步后即可实现sitemap中调用tag链接。