PbootCMS自带的sitemap.xml增加tag标签链接

COS、CDN
wdzsjl 5个月前 (10-28) 阅读数 276 #PbootCMS
  1. 修改 SitemapModel.php 文件

    • 打开 /apps/home/model/SitemapModel.php 文件
    • 在 78 行后面增加以下代码:
      • 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; }
      修改 SitemapController.php 文件
    • 打开 /apps/home/controller/SitemapController.php 文件
    • 在 73 行后面增加以下代码:
      • if (!empty($rs = $this->model->getSortTags(''))) { $tags = implode(',', $rs); $tags = array_unique(explode(',', $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.xml 即可看到生成的带有 tag 的链接地址。
COS、CDN
热门