5 求问题列表页seo设置,开启分类时分类列表seo设置。

目前后台只能设置首页话题问题文章的内页,求列表页设置方法,开启分类时,分类列表页title能显示分类名称。

请先 登录 后评论

最佳答案 2017-06-27 11:38

问题列表seo设置方法如下:

1、控制器获取当前分类对象

        $parentId=$currentCategoryId = 0;
        $currentCategory = null;
        if( $categorySlug != 'all' ){
            $category = Category::where("slug","=",$categorySlug)->first();
            $currentCategory = $category;
            if(!$category){
                abort(404);
            }
            $currentCategoryId = $category->id;
            $parentId = $category->parent_id;
            if($category->hasChild()){
                $parentId = $category->id;
            }
        }
2、将currentCategory 设置为view层可以使用
        return view('theme::home.ask')->with(compact('currentCategory','questions','hotUsers','hotTags','filter','categories','currentCategoryId','parentId','parentCategories','categorySlug'));
里面加入了 currentCategory。

3、在问题列表页面 ask.blade.php中可以使用 $currentCategory->name 获取到分类名称,不过需要注意一下$currentCategory是否存在,需要先做一个判断,存在则显示。
@if($currentCategory) $currentCategory->name @endif
请先 登录 后评论

其它 1 个回答

大唐营销老胡 - SEO教程:www.datangyingxiao.com

代码完美解决。   对于php代码不太熟悉的朋友可能比较麻烦  研究一下

请先 登录 后评论