texnixe/related

根据给定字段的值获取相关页面或文件

安装: 93

依赖项: 0

建议者: 0

安全: 0

星星: 23

关注者: 1

分支: 2

开放问题: 2

类型:kirby-plugin

1.0.2 2021-01-26 19:13 UTC

This package is auto-updated.

Last update: 2024-09-20 02:28:42 UTC


README

GitHub release License Kirby 3 Pluginkit

Kirby 相关

Kirby 3 相关是一个 Kirby CMS 插件,允许您根据给定字段中匹配的值获取与当前页面/文件相关的页面或文件。结果集合按匹配次数排序,作为相关性的指示。

示例:当前页面有一个包含三个值(红色、绿色、蓝色)的标签字段。您想要找到所有至少有两个匹配标签值的同级页面。

商业使用

此插件是免费的,但如果您将其用于商业项目,请考虑

安装

下载

下载文件 并将其放置在 site/plugins/kirby-related 内。

Git 子模块

您可以将插件作为 Git 子模块添加。

$ cd your/project/root
$ git submodule add https://github.com/texnixe/kirby3-related.git site/plugins/kirby-related
$ git submodule update --init --recursive
$ git commit -am "Add Kirby Related plugin"

运行以下命令以更新插件

$ cd your/project/root
$ git submodule foreach git checkout master
$ git submodule foreach git pull
$ git commit -am "Update submodules"
$ git submodule update --init --recursive

用法

相关页面

<?php

$relatedPages = $page->related($options);

foreach($relatedPages as $p) {
  echo $p->title();
}

相关文件

<?php

$relatedImages = $image->related($options);

foreach($relatedImages as $image) {
  echo $image->filename();
}

配置选项

您可以使用 texnixe.related.cache 选项将缓存设置为 true 或 false。

return [
  'texnixe.related.cache' => true
];

选项

您可以通过传递一个选项数组

<?php
$relatedPages = $page->related(array(
  'searchCollection' => $page->siblings()->visible(),
  'searchField'      => 'tags',
  'matches'          => 2,
  'delimiter'        => ',',
  'languageFilter'   => false
  ));
?>

searchCollection

要搜索的页面集合。默认:$page->siblings()

searchField

要搜索的字段名称。默认:tags

delimiter

您在字段中用于分隔值的分隔符。默认:,

matches

应匹配的最小值数。默认:1

languageFilter

在多语言安装中按语言过滤相关项。默认:false

免责声明

此插件提供“原样”且无任何保证。请自行承担使用风险,并在将其用于生产环境之前自行测试。如果您遇到任何问题,请 创建一个问题

许可证

MIT

不建议在任何推广种族主义、性别歧视、恐同症、动物虐待、暴力或其他任何形式仇恨言论的项目中使用此插件。