pbootcms多语言限制sitemap只调用英文en内容
代码如下:
<?php /** * @copyright (C)2016-2099 Hnaoyun Inc. * @author XingMeng * @emAIl hnxsh@foxmail.com * @date 2018年2月14日 * Sitemap模型 */ namespace app\home\model; use core\basic\Model; class SitemapModel extends Model { // 分类栏目列表 public function getSorts() { $fields = array( 'a.id', 'a.pcode', 'a.scode', 'a.name', 'a.filename', 'a.outlink', 'b.type', 'b.urlname' ); $join = array( 'ay_model b', 'a.mcode=b.mcode', 'LEFT' ); $result = parent::table('ay_content_sort a')->field($fields) ->where('a.status=1') ->where("a.acode = 'en'") // 只取 en 数据 ->join($join) ->order('CASE WHEN a.pcode = 0 THEN 1 ELSE 2 END, a.pcode, a.sorting, a.id') ->select(); return $result; } // 指定列表内容 public function getSortContent($scode) { $fields = array( 'a.id', 'a.filename', 'a.date', 'c.type', 'c.urlname', 'b.scode', 'b.filename as sortfilename' ); $join = array( array( 'ay_content_sort b', 'a.scode=b.scode', 'LEFT' ), array( 'ay_model c', 'b.mcode=c.mcode', 'LEFT' ) ); $where = array( 'a.status=1', 'c.type=2', "a.date<'" . date('Y-m-d H:i:s') . "'", "a.acode = 'en'" // 只取 en 数据 ); return parent::table('ay_content a')->field($fields) ->where("a.scode='$scode'") ->where($where) ->join($join) ->order('a.id') ->select(); } // 获取所有数据(首页、栏目页、文章页)并排序 public function getAllSortedData() { // 获取栏目页数据 $sorts = $this->getSorts(); // 模拟首页数据,这里假设首页有特定的 scode 为 'home',需要根据实际情况修改 $homePage = [ [ 'id' => 0, 'pcode' => 0, 'scode' => 'home', 'name' => 'Home Page', 'filename' => 'index.html', 'outlink' => '', 'type' => 0, 'urlname' => '' ] ]; $allData = array_merge($homePage, $sorts); // 获取文章页数据 foreach ($sorts as $sort) { $content = $this->getSortContent($sort['scode']); $allData = array_merge($allData, $content); } return $allData; } }
