Winter/wn-blog-plugin

Winter CMS 的博客插件

资助包维护!
wintercms
Open Collective

安装数量: 23,922

依赖项: 2

建议者: 0

安全性: 0

星标: 17

关注者: 5

分支: 21

开放问题: 9

类型:winter-plugin

v2.1.3 2024-04-08 17:33 UTC

This package is auto-updated.

Last update: 2024-09-22 17:57:07 UTC


README

Winter CMS 的一个简单、可扩展的博客平台。

博客和论坛构建教程视频

安装

此插件可以通过 Composer 进行安装。

composer require winter/wn-blog-plugin

编辑帖子

插件使用 Markdown 标记语言来编写帖子。您可以使用任何 Markdown 语法以及一些特殊标签来嵌入图片和视频(需要 Winter Blog Video 插件)。要嵌入图片,请使用图片占位符

![1](image)

第一个数字是占位符索引。如果您在一个帖子中使用多张图片,您应该为每张图片使用一个唯一的索引

![1](image)

![2](image)

您还可以通过使用 markdown extra 语法为图片添加类或 ID

![1](image){#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 - 要按其筛选帖子的分类 slug。如果为空,则显示所有帖子。
  • postsPerPage - 在单页上显示的帖子数量(自动支持分页)。默认值为 10。
  • noPostsMessage - 在空帖子列表中显示的消息。
  • sortOrder - 用于帖子排序顺序的列名和方向。默认值为 published_at desc
  • categoryPage - 分类页面的路径。默认值是 blog/category - 它与主题目录中的 pages/blog/category.htm 文件匹配。此属性用于默认组件部分以创建指向博客类别的链接。
  • postPage - 帖子详情页面的路径。默认值是 blog/post - 它与主题目录中的 pages/blog/post.htm 文件匹配。此属性用于默认组件部分以创建指向博客帖子的链接。
  • exceptPost - 通过其 slug 或唯一 ID 忽略单个帖子。被忽略的帖子将不会包含在列表中,对于显示其他/相关帖子很有用。
  • exceptCategories - 忽略来自逗号分隔的类别列表的帖子,列表中给出的是唯一的slug。被忽略的帖子将不会包含在列表中。

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/winter/blog/components/posts/default.htm 中编码。如果默认标记不适合您的网站,您可以从默认部分复制它,并将上面的示例中的 {% component %} 调用替换为部分内容。

帖子页面

使用 blogPost 组件在页面上显示博客帖子。该组件有以下属性

  • slug - 用于通过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/winter/blog/components/post/default.htm 中编码。

类别列表

使用 blogCategories 组件显示带有链接的博客帖子类别列表。该组件有以下属性

  • slug - 用于通过slug查找当前类别的值。默认值是 {{ :slug }} 以从路由参数 :slug 获取值。
  • displayEmpty - 确定是否显示空类别。默认值是 false。
  • categoryPage - 分类页面的路径。默认值是 blog/category - 它与主题目录中的 pages/blog/category.htm 文件匹配。此属性用于默认组件部分以创建指向博客类别的链接。

组件将以下变量注入到使用它的页面

  • categoryPage - 包含 categoryPage 组件属性的值。
  • categories - 从数据库中加载的博客类别列表。
  • currentCategorySlug - 当前类别的slug。此属性用于在类别列表中标记当前类别。

该组件可以在任何页面上使用。下一个示例展示了在博客主页上基本组件的使用

title = "Blog"
url = "/blog/:page?"

[blogCategories]
==
...
<div class="sidebar">
    {% component 'blogCategories' %}
</div>
...

类别列表在默认组件部分 plugins/winter/blog/components/categories/default.htm 中编码。

RSS源

使用 blogRssFeed 组件显示包含最新博客帖子的RSS源。以下属性被支持

  • categoryFilter - 要按其筛选帖子的分类 slug。如果为空,则显示所有帖子。
  • 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}
![1](image){#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会将所有出现的HTMLPHP转换为以下内容

<abbr title="Hyper Text Markup Language">HTML</abbr>
<abbr title="Hypertext Preprocessor">PHP</abbr>