xinix / wn-blog-plugin
Winter CMS 的博客插件
Requires
- php: >=7.0
- composer/installers: ~1.0
This package is auto-updated.
Last update: 2024-09-17 20:53:23 UTC
README
Winter CMS 的一个简单、可扩展的博客平台。
编辑文章
插件使用 Markdown 标记文章。您可以使用任何 Markdown 语法以及一些特殊标签来嵌入图片和视频(需要 Winter Blog Video 插件)。要嵌入图片,请使用图片占位符

第一部分中的数字是占位符索引。如果您在一篇文章中使用多个图片,您应该为每个图片使用唯一的索引


您还可以通过使用 markdown extra 语法为图片添加类或 ID
{#id .class}
摘要与阅读更多
通过从菜单中选择 博客 > 文章 来管理文章。每个文章可以包含一个摘要,您可以在 管理 选项卡中的此字段输入一些文本。该内容使用博客文章的 summary
属性在页面上显示。
{{ post.summary|raw }}
或者,此字段可以留空,摘要可以由主内容(编辑 选项卡)捕获。使用特殊标签 <!-- more -->
指定主内容的摘要,此标签以上的所有内容将被视为摘要。例如
This is a great introduction to a great blog post. This text is included as part of the excerpt / summary.
<!-- more -->
Let's dive in to more detail about why this post is so great. This text will not be included in the summary.
最后,如果没有指定摘要且未使用“更多”标签,则博客文章将捕获内容的第一个 600 个字符并用作摘要。
实现前端页面
插件提供了一些组件来构建文章列表页面(存档)、分类页面、文章详情页面和侧边栏的分类列表。
文章列表页面
使用 blogPosts
组件在页面上显示最新博客文章的列表。该组件具有以下属性
- pageNumber - 该值用于确定用户所在的页面,它应该是默认标记的路由参数。默认值是 {{ :page }},用于从路由参数
:page
获取值。 - categoryFilter - 用于过滤文章的分类别名。如果留空,则显示所有文章。
- postsPerPage - 每页显示的文章数量(支持自动分页)。默认值是 10。
- noPostsMessage - 在空文章列表中显示的消息。
- sortOrder - 用于文章排序顺序的列名和方向。默认值是 published_at desc。
- categoryPage - 分类页面的路径。默认值是 blog/category - 它与主题目录中的 pages/blog/category.htm 文件匹配。此属性用于默认组件部分,用于创建博客类别的链接。
- postPage - 文章详情页面的路径。默认值是 blog/post - 它与主题目录中的 pages/blog/post.htm 文件匹配。此属性用于默认组件部分,用于创建博客文章的链接。
- exceptPost - 通过其别名或唯一 ID 忽略单个文章。被忽略的文章将不会包含在列表中,对于显示其他/相关文章很有用。
- exceptCategories - 忽略由逗号分隔的类别列表中的帖子,这些类别通过其唯一的缩写给出。被忽略的帖子将不会包含在列表中。
blogPosts 组件将其以下变量注入到其使用的页面
- posts - 从数据库中加载的博客帖子列表。
- postPage - 包含
postPage
组件属性的值。 - category - 从数据库中加载的博客类别对象。如果未找到类别,变量值为 null。
- categoryPage - 包含
categoryPage
组件属性的值。 - noPostsMessage - 包含
noPostsMessage
组件属性的值。
该组件支持分页,并从 :page
URL 参数中读取当前页码索引。以下示例显示了在博客主页上基本组件的使用
title = "Blog"
url = "/blog/:page?"
[blogPosts]
postsPerPage = "5"
==
{% component 'blogPosts' %}
以下示例显示了带有类别过滤的基本组件使用
title = "Blog Category"
url = "/blog/category/:slug/:page?"
[blogPosts]
categoryFilter = "{{ :slug }}"
==
function onEnd()
{
// Optional - set the page title to the category name
if ($this->category)
$this->page->title = $this->category->name;
}
==
{% if not category %}
<h2>Category not found</h2>
{% else %}
<h2>{{ category.name }}</h2>
{% component 'blogPosts' %}
{% endif %}
帖子列表和分页在默认组件部分 plugins/xinix/blog/components/posts/default.htm
中编码。如果默认标记不适合您的网站,您可以将其从默认部分复制出来,并用部分内容替换上述示例中的 {% component %}
调用。
帖子页面
使用 blogPost
组件在页面上显示博客帖子。该组件具有以下属性
- slug - 用于通过其缩写查找帖子的值。默认值为 {{ :slug }},从路由参数
:slug
获取值。 - categoryPage - 分类页面的路径。默认值是 blog/category - 它与主题目录中的 pages/blog/category.htm 文件匹配。此属性用于默认组件部分,用于创建博客类别的链接。
该组件将其以下变量注入到其使用的页面
- post - 从数据库中加载的博客帖子对象。如果未找到帖子,变量值为 null。
以下示例显示了在博客页面上基本组件的使用
title = "Blog Post"
url = "/blog/post/:slug"
[blogPost]
==
<?php
function onEnd()
{
// Optional - set the page title to the post title
if ($this->post)
$this->page->title = $this->post->title;
}
?>
==
{% if post %}
<h2>{{ post.title }}</h2>
{% component 'blogPost' %}
{% else %}
<h2>Post not found</h2>
{% endif %}
帖子详情在默认组件部分 plugins/xinix/blog/components/post/default.htm
中编码。
类别列表
使用 blogCategories
组件显示带链接的博客帖子类别列表。该组件具有以下属性
- slug - 用于通过其缩写查找当前类别的值。默认值为 {{ :slug }},从路由参数
:slug
获取值。 - displayEmpty - 确定是否显示空类别。默认值为 false。
- categoryPage - 分类页面的路径。默认值是 blog/category - 它与主题目录中的 pages/blog/category.htm 文件匹配。此属性用于默认组件部分,用于创建博客类别的链接。
该组件将其以下变量注入到其使用的页面
- categoryPage - 包含
categoryPage
组件属性的值。 - categories - 从数据库中加载的博客类别列表。
- currentCategorySlug - 当前类别的缩写。此属性用于在类别列表中标记当前类别。
该组件可以在任何页面上使用。以下示例显示了在博客主页上基本组件的使用
title = "Blog"
url = "/blog/:page?"
[blogCategories]
==
...
<div class="sidebar">
{% component 'blogCategories' %}
</div>
...
类别列表在默认组件部分 plugins/xinix/blog/components/categories/default.htm
中编码。
RSS源
使用 blogRssFeed
组件显示包含最新博客帖子的RSS源。以下属性受支持
- categoryFilter - 用于过滤文章的分类别名。如果留空,则显示所有文章。
- postsPerPage - 在源中显示的帖子数。默认值为 10。
- blogPage - 主要博客页面的路径。默认值为 blog - 它与主题目录中的 pages/blog.htm 文件匹配。此属性用于在RSS源中创建指向主要博客页面的链接。
- postPage - 帖子详情页面的路径。默认值为 blog/post - 它与主题目录中的 pages/blog/post.htm 文件匹配。此属性用于在RSS源中创建指向博客帖子的链接。
该组件可以在任何页面上使用,它将劫持整个页面周期以以RSS格式显示源。以下示例显示了如何使用它
title = "RSS Feed"
url = "/blog/rss.xml"
[blogRssFeed]
blogPage = "blog"
postPage = "blog/post"
==
<!-- This markup will never be displayed -->
Markdown指南
Winter CMS 支持 标准markdown语法 以及 扩展markdown语法
类和ID
可以将类和ID添加到图片和其他元素中,如下所示
[link](url){#id .class}
{#id .class}
# Winter CMS {#id .class}
代码块
Markdown extra 允许使用代码块。使用代码块时,您不需要对要标记为代码的区域进行缩进
```
Code goes here
```
您还可以使用 ~
符号
~~~
Code goes here
~~~
表格
一个 简单 的表格可以定义如下
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
如果您想,您还可以添加前导和尾随管道
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
要为单元格添加对齐,只需在分隔符的开始或结尾处添加一个 :
| First Header | Second Header |
| :------------ | ------------: |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
要使单元格居中对齐,只需在两侧都添加 :
| First Header | Second Header |
| ------------- | :-----------: |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
定义列表
以下是一个简单定义列表的示例
Laravel
: A popular PHP framework
Winter CMS
: Awesome CMS built on Laravel
一个术语也可以有多个定义
Laravel
: A popular PHP framework
Winter CMS
: Awesome CMS built on Laravel
: Supports markdown extra
您还可以将多个术语与一个定义关联起来
Laravel
Winter CMS
: Built using PHP
脚注
使用 markdown extra,可以创建参考样式的脚注
This is some text with a footnote.[^1]
[^1]: And this is the footnote.
缩写
使用 markdown extra,您可以在标记中添加缩写。要使用此功能,首先创建一个定义列表
*[HTML]: Hyper Text Markup Language
*[PHP]: Hypertext Preprocessor
现在 markdown extra 将将所有出现的 HTML
和 PHP
转换如下
<abbr title="Hyper Text Markup Language">HTML</abbr>
<abbr title="Hypertext Preprocessor">PHP</abbr>