- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
October CMS如何过滤多个类别的博文?我正在使用 RainLab 博客插件。该插件只允许过滤一个类别。我想要一个综合结果。请帮忙。
最佳答案
您将需要使用一些自定义代码来根据多个类别进行过滤。如果仍在使用 PostList 组件,请进行以下更改,您将能够根据多个类别过滤列表。
我在下面所做的是修改 PostList 组件,首先将其 fork 并将 posts
变量替换为 filteredPosts
变量。然后,为了设置 filteredPosts
,代码被编写为获取所有博客文章并仅返回那些包含在 $categories
数组中的类别。 不可否认,这种方法绝对不是最有效的,可以进一步改进
在标记
中添加以下代码<ul class="post-list">
{% for post in filteredPosts %}
<li>
<h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
<p class="info">
Posted
{% if post.categories.count %} in {% endif %}
{% for category in post.categories %}
<a href="{{ category.url }}">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
{% endfor %}
on {{ post.published_at|date('M d, Y') }}
</p>
<p class="excerpt">{{ post.summary|raw }}</p>
</li>
{% else %}
<li class="no-data">{{ noPostsMessage }}</li>
{% endfor %}
</ul>
{% if posts.lastPage > 1 %}
<ul class="pagination">
{% if posts.currentPage > 1 %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage-1) }) }}">← Prev</a></li>
{% endif %}
{% for page in 1..posts.lastPage %}
<li class="{{ posts.currentPage == page ? 'active' : null }}">
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
</li>
{% endfor %}
{% if posts.lastPage > posts.currentPage %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam):(posts.currentPage+1) }) }}">Next →</a></li>
{% endif %}
</ul>
{% endif %}
在 CMS 的代码选项卡中添加以下代码。改变
use RainLab\Blog\Models\Post as BlogPost;
function onStart(){
//This is where you list the categories you want to display
$categories = ['cat-a','cat-b'];
$posts = [];
foreach(BlogPost::all() as $blog){
foreach($blog->categories as $cat){
if(in_array($cat->slug, $categories)) {
array_push($posts, $blog);
break;
}
}
}
$this['filteredPosts'] = $posts;
}
关于octobercms - 如何在 octobercms 中过滤具有多个类别的博客文章?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49952555/
我只是想知道如何在前端的octobercms中上传多个文件没有教程, 我正在使用 然后只得到最后上传的图像 $posting->posting->image=Input::file('posting
我只是想知道如何在前端的octobercms中上传多个文件没有教程, 我正在使用 然后只得到最后上传的图像 $posting->posting->image=Input::file('posting
根据 this section在十月CMS文档中,我应该可以设置这样的目录结构: pluginname ├── components │ ├── resumefilter │ │ ├──
October CMS如何过滤多个类别的博文?我正在使用 RainLab 博客插件。该插件只允许过滤一个类别。我想要一个综合结果。请帮忙。 最佳答案 您将需要使用一些自定义代码来根据多个类别进行过滤。
我想在后端渲染列表中显示图像。为此,如何获取显示图像的路径。我们试过 base_path() 方法。 但它给了我像“opt/lampp/htdocs/ashish/”这样的完整路径,但我想得到http
我运行了 php artisan october:env,我想知道如何在 View 中使用环境变量。 例如:
我运行了 php artisan october:env,我想知道如何在 View 中使用环境变量。 例如:
这是我的代码块,我想将 service 变量传递给组件。 {% for service in services %}
默认情况下,用户会被重定向到仪表板。我该如何更改它以便将用户重定向到我的插件页面? 最佳答案 后端 Controller 触发 backend.page.beforeDisplay 事件,我们可以在我
我是 10 月的新手,遇到了一个我无法解决的问题。当我从命令行创建一个插件,然后运行 插件:刷新 数据库中的表没有被创建。 version.yaml 根据文档是正确的。以下是文件的内容。 插件/M
我使用 Builder Plugin 创建了一个插件(将其称为产品)在它里面,我有一个下拉菜单(称之为product_category(产品类别)) 使用Builder Plugin,我添加了一些Ke
我使用 translate.rainlab 插件进行本地化,但不确定如何翻译 ajax 表单的 Flash 消息。 function onMailSend() { Mail::sendTo('
想知道是否有一种简单的方法来格式化后端列表列值。将数值作为货币的示例 最佳答案 晚了,但供引用: 如果仅用于后端列表,您可以轻松创建一个新的列类型 Currency 并使用它。 see documen
我正在使用 the following code (在页面的代码部分)将用户重定向到登录页面,如果他们没有登录: function onStart() { $user = $this->acc
我对 octobercms 非常陌生,并且有使用 laravel 4.2 的经验。 我想问如何在cmd中使用artisan创建表格?或者是在octobercms中不需要使用cmd来创建表?有详细教程的
鉴于以下代码: $car= new Car(); $car->name = Input::get('name'); $car->photo = Input::file('photo'); $car->
我是 octobercms 的新手,我想列出我项目中所有现有的命名空间和插件和模型,我该怎么做? 最佳答案 public function test_stat() { if(is_dir(('
我正在 October CMS 构建器上制作一个插件。在后端创建了几个数据库表、模型和表单。现在尝试添加表单元素(复选框)并希望从其他表中获取复选框值。 示例: Table 1: categories
我正在使用以下数据库配置 'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost'
在我的一个页面中,我像这样执行数据库查询.. function onStart() { $this['numz'] = Db::table('backend_users')->select('
我是一名优秀的程序员,十分优秀!