【问题标题】:October CMS Rainlab Blog plugin get current category name?十月 CMS Rainlab 博客插件获取当前类别名称?
【发布时间】:2016-01-02 19:49:03
【问题描述】:

我正在尝试使用 Rainlab 博客插件在十月 CMS 上创建博客,并且在我的类别页面上,我想将当前类别的名称作为标题。我无法弄清楚如何做到这一点,文档中没有关于获取当前类别的任何内容,Google 也无法为我找到它。

【问题讨论】:

    标签: php laravel octobercms


    【解决方案1】:

    只需在类别模板中使用 {{ category.name }} 即可。

    如果您没有自定义类别模板(并且正在使用插件中的默认模板),那么您需要将一个添加到您的主题中。我的看起来像这样:

        title = "Blog Category"
        url = "/blog/category/:slug/:page?"
        layout = "default"
    
        [blogPosts]
        categoryFilter = "{{ :slug }}"
    
        ==
        function onEnd()
        {
            // Optional - set the page title to the category name
            if ($this->category)
                $this->page->title = $this->category->name;
        }
        ==
    
        <div class="container blog-category">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
    
                            {% if not category %}
                                <h1>Category not found</h1>
                            {% else %}
                                <h1>{{ category.name }}</h1>
    
                        {% for post in posts %}
    
                        {% partial "blog/list-single" post=post %}
    
                        {% else %}
    
                            <div class="no-data">{{ noPostsMessage }}</div>
    
                        {% endfor %}
    
                            {% endif %}
    
                        </div>
                </div>
        </div>
    

    【讨论】:

    • 嗨 Staple 如果您使用 utopigs 插件,将如何实现这一点,因为我无法解析类别名称或标题我只是得到没有类别名称的博客类别
    猜你喜欢
    • 2018-04-20
    • 2018-11-26
    • 1970-01-01
    • 2017-03-10
    • 2019-08-24
    • 2018-11-22
    • 2018-08-09
    • 1970-01-01
    • 2019-01-09
    相关资源
    最近更新 更多