pbootcms默認(rèn)生成的sitemap.xml中是不含tag標(biāo)簽鏈接的,如果我們想要實(shí)現(xiàn)在sitemap.xml直接生成tags標(biāo)簽,這個(gè)要怎么操作呢?
實(shí)現(xiàn)步驟
養(yǎng)好習(xí)慣,修改這些文件之前做好備份。1、打開(kāi)/apps/home/model/SitemapModel.php,在78行后面增加個(gè)指定分類標(biāo)簽調(diào)用代碼。
// 指定分類標(biāo)簽調(diào)用
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、打開(kāi)/apps/home/controller/SitemapController.php,在73行后面增加
if (! ! $rs = $this->model->getSortTags('')) {
$tags = implode(',', $rs); // 把欄目tags串起來(lái)
$tags = array_unique(explode(',', $tags)); // 再把所有tags組成數(shù)組并去重
foreach ($tags as $key2 => $value2) {
if (! in_array($value2, array_column($data, 'tags'))) { // 避免重復(fù)輸出
$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');
}
}
}
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!