delaneymethod/craft-category-groups 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

delaneymethod/craft-category-groups

Composer 安装命令:

composer require delaneymethod/craft-category-groups

包简介

Two field types for Craft CMS that lets you select one or more Category Groups or one or more Categories from one or more Category Groups.

README 文档

README

Two field types for Craft CMS that:

  • lets you select one or more Category Groups.
  • lets you select one or more Categories from one or more Category Groups.

Install

  1. Add the repo to your project and install via Composer:
cd /path/to/project

composer require delaneymethod/category-groups && php craft plugin/install category-groups

Usage

CategoryGroupField

  • In the dropdown/radio buttons mode your field normalizes to a CategoryGroup|null.
  • In checkbox mode you return an array<CategoryGroup>.

Print the selected group name(s):

{% set fieldValue = entry.myCategoryGroupsFieldHandle ?? null %}
{% if fieldValue %}
	{% if fieldValue is instance of('craft\\models\\CategoryGroup') %}
		<p>Selected category group: {{ fieldValue.name }}</p>
	{% elseif fieldValue is iterable %}
		<p>Selected category groups:</p>
		<ul>
			{% for categoryGroup in fieldValue %}
				<li>{{ categoryGroup.name }}</li>
			{% endfor %}
		</ul>
	{% elseif fieldValue is string %}
		{% set categoryGroup = craft.app.categories.getGroupByUid(fieldValue) %}
		{% if categoryGroup %}
			<p>Selected category group: {{ categoryGroup.name }}</p>
		{% endif %}
	{% else %}
		<p>No category group selected.</p>
	{% endif %}
{% else %}
	<p>No category groups selected.</p>
{% endif %}

Use the selected category group to list its categories (current site)

{% if fieldValue is instance of('craft\\models\\CategoryGroup') %}
	{% set categories = craft.categories().groupId(fieldValue.id).siteId(craft.app.sites.currentSite.id).status(null).orderBy('title asc').all() %}
	{% if categories %}
		<h4>Category group: {{ fieldValue.name }}</h4>
		<ul>
			{% for category in categories %}
				<li><a href="{{ category.url }}">{{ category.title }}</a></li>
			{% endfor %}
		</ul>
	{% else %}
		<p><em>No categories found in {{ fieldValue.name }}.</em></p>
	{% endif %}
{% elseif fieldValue is iterable %}
	{% for categoryGroup in fieldValue %}
		{% set categories = craft.categories().groupId(categoryGroup.id).siteId(craft.app.sites.currentSite.id).status(null).orderBy('title asc').all() %}
		{% if categories %}
			<h4>Category group: {{ categoryGroup.uid }}</h4>
			<ul>
				{% for category in categories %}
					<li><a href="{{ category.url }}">{{ category.title }}</a></li>
				{% endfor %}
			</ul>
		{% else %}
			<p><em>No categories found in {{ categoryGroup.name }}.</em></p>
		{% endif %}
	{% endfor %}
{% elseif fieldValue is string %}
	{% set categoryGroup = craft.app.categories.getGroupByUid(fieldValue) %}
	{% if categoryGroup %}
		{% set categories = craft.categories().groupId(categoryGroup.id).siteId(craft.app.sites.currentSite.id).status(null).orderBy('title asc').all() %}
		{% if categories %}
			<h4>Category group: {{ categoryGroup.name }}</h4>
			<ul>
				{% for category in categories %}
					<li><a href="{{ category.url }}">{{ category.title }}</a></li>
				{% endfor %}
			</ul>
		{% else %}
			<p><em>No categories found for {{ categoryGroup.name }}.</em></p>
		{% endif %}
	{% else %}
		<p><em>No category group found for {{ fieldValue }}.</em></p>
	{% endif %}
{% endif %}

CategoryGroupsField

  • Normalizes to a CategoryQuery.
  • You can iterate, count, limit, etc.

List selected categories (title + group)

{% set categoryQuery = entry.myCategoryMultipleGroupsFieldHandle ?? null %}
{% if categoryQuery %}
	{% set categories = categoryQuery.status(null).all() %}
	{% if categories %}
		<ul>
			{% for category in categories %}
				<li><a href="{{ category.url }}">{{ category.title }}</a> ({{ category.group.name }})</li>
			{% endfor %}
		</ul>
	{% else %}
		<p>No categories selected.</p>
	{% endif %}
{% else %}
	<p>No categories selected.</p>
{% endif %}

Count / limit / paginate

{% set categoryQuery = entry.myCategoryMultipleGroupsFieldHandle ?? null %}
{% if categoryQuery %}
	{% set count = categoryQuery.count() }}
	{% if count > 1 %}
		<p>{{ count }} categories selected.</p>
	{% else %}
		<p>1 category selected.</p>
	{% endif %}
	
	{% set firstFiveCategories = categoryQuery.status(null).limit(5).all() %}
	{% if firstFiveCategories %}
		<p>First five categories:</p>
		<ul>
			{% for category in firstFiveCategories %}
				<li><a href="{{ category.url }}">{{ category.title }}</a></li>
			{% endfor %}
		</ul>
	{% endif %}
{% endif %}

delaneymethod/craft-category-groups 适用场景与选型建议

delaneymethod/craft-category-groups 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「category」 「categories」 「cms」 「multi」 「groups」 「Craft」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 delaneymethod/craft-category-groups 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 delaneymethod/craft-category-groups 我们能提供哪些服务?
定制开发 / 二次开发

基于 delaneymethod/craft-category-groups 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-30