sunadarake/sculpin-related-posts-bundle

第三方Sculpin插件包,用于创建相关帖子

1.0.1 2021-03-13 08:00 UTC

This package is auto-updated.

Last update: 2024-09-13 15:48:44 UTC


README

第三方Sculpin插件包,用于在Sculpin博客中创建相关帖子。

设置

安装此插件包的推荐方法是使用Composer。

composer require sunadarake/sculpin-related-posts-bundle

在您的app/SculpinKernel.php文件中添加此插件包。

<?php

use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;
use Darake\SculpinRelatedPostsBundle\SculpinRelatedPostsBundle;

class SculpinKernel extends AbstractKernel
{
    protected function getAdditionalSculpinBundles(): array
    {
        return [
            SculpinRelatedPostsByTaxonomyBundle::class,
        ];
    }
}

如何使用

如果您在_posts/example.md文件中写下以下内容,

```
title: "exampleTitile"
```
exampleText

则在_views/post.html文件中写下以下内容。

{% if page.related %}
<ul>
    {% for related in page.related %}
    <li><a href="{{ site.url }}{{ related.data.get('url') }}">{{ related.title }}</a></li>
    {% endfor %}
</ul>
{% endif %}

上述代码将输出如下

<ul>
    <li><a href="https://:8000/php-array.html">The 10 most useful PHP array functions</a></li>
    <li><a href="https://:8000/php-libraries.html">How to use PHP libraries by composer</a></li>
    <li><a href="https://:8000/zend-engine.html">How Zend Engine works</a></li>
    <li><a href="https://:8000/php-history.html">PHP history from 2000 to 2021</a></li>
    <li><a href="https://:8000/php-debugging.html">Tutorial: Debuggin in PHP</a></li>
</ul>

配置max_per_page

如果您想更改相关帖子的数量,请在app/config/sculpin_kernel.yml中配置max_per_page。(默认的max_per_page为5)

sculpin_content_types:
    posts:
        permalink: pretty
sculpin_related_posts:
    max_per_page: 3