diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 4b47a3f..213b7fc 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -5,11 +5,13 @@ namespace app\admin\controller; use app\common\model\AdminAuth; use app\common\model\Document; use app\common\model\Document as DocumentModel; +use app\common\model\Tag as TagModel; use app\common\model\DocumentCategory; use app\common\model\DocumentCategory as DocumentCategoryModel; use app\common\model\FriendLink; use app\common\model\MessageForm; use app\common\model\AdminNotify; +use app\common\model\Tag; use app\common\model\User; use Exception; use think\db\exception\DataNotFoundException; @@ -87,11 +89,9 @@ class Index extends AuthController //获取域名 $domain = Request::domain(); //获取页码 - $page = input('page/d'); - if (!$page) { - $page = 1; - } + $page = input('page/d')?:1; $str = ''; + $pagesize = 100; if ($page == 1) { if (file_exists('sitemap.xml')) unlink('sitemap.xml'); @@ -104,27 +104,23 @@ class Index extends AuthController $str .= 'daily'; $str .= '1.0'; $str .= ''; - } - $pagesize = 100; - //获取文章分类url - $documentCategoryModel = new DocumentCategoryModel(); - $categoryInfo = $documentCategoryModel->field('id,alias,title,create_time') - ->where('status', 1) - ->page($page, $pagesize) - ->order('id desc')->select(); - foreach ($categoryInfo as $v) { - echo $v['create_time']; - echo date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])); - echo strtotime($v['create_time']);die(); - $str .= ''; - $str .= '' . url('index/article/lists',["id"=>$v["alias"]?:$v['id']],".html",$domain) . ''; - $str .= '' . date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) . ''; - $str .= 'always'; - $str .= '0.8'; - $str .= ''; + //获取文章分类url + $documentCategoryModel = new DocumentCategoryModel(); + $categoryInfo = $documentCategoryModel->field('id,alias,title,create_time') + ->where('status', 1) + ->page($page, $pagesize) + ->order('id desc')->select(); + foreach ($categoryInfo as $v) { + $str .= ''; + $str .= '' . url('index/article/lists',["id"=>$v['id']],".html",$domain) . ''; + $str .= '' . date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) . ''; + $str .= 'always'; + $str .= '0.8'; + $str .= ''; + } } - //获取详细页分类url + //获取文章URL $documentModel = new DocumentModel(); $documentInfo = $documentModel->field('id,alias,create_time') ->where('display', 1) @@ -132,16 +128,31 @@ class Index extends AuthController ->order('id desc')->select(); foreach ($documentInfo as $v) { - echo date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])); - echo strtotime($v['create_time']);die(); $str .= ''; - $str .= '' . url('/index/article/detail',["id"=>$v["alias"]?:$v['id']],".html",$domain) . ''; + $str .= '' . url('/article/detail',["id"=>$v["alias"]?:$v['id']],".html",$domain) . ''; $str .= ''.date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) .''; $str .= 'monthly'; $str .= '0.6'; $str .= ''; } - if (count($categoryInfo) < $pagesize && count($documentInfo) < $pagesize) { + + //获取文章标签页url + $documentModel = new TagModel(); + $documentInfo = $documentModel->field('name,create_time') + ->page($page, $pagesize) + ->group('name') + ->order('name desc')->select(); + + foreach ($documentInfo as $v) { + $str .= ''; + $str .= '' . url('/article/tag',["t"=>$v["name"]],".html",$domain) . ''; + $str .= ''.date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) .''; + $str .= 'monthly'; + $str .= '0.6'; + $str .= ''; + } + + if (count($documentInfo) < $pagesize) { $str .= ''; return (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) ? $this->failedNotice("站点地图更新失败!", "/admin/") :