挂钩:post.frontend_url
Last updated on Jun 24, 2026 01:40
## 概述
类型: 过滤器
位置: app/Models/Category.php
过滤类别的公共 URL。当访问 $category->frontend_url 时调用。主题可以使用它为类别档案创建自定义 URL 结构。
## 参数
| 参数 | 类型 | 描述 |
|---|---|---|
$url |
string | 默认类别 URL |
$post |
Post | 类别模型实例 |
## 返回
必须返回 string - 最终 URL。
使用示例
在文档主题的类别 URL 中使用父级 slug:
Hook::addFilter('category.frontend_url', function (string $url, $category) {
if ($category->parent && $category->parent->slug === 'documentation') {
return '/docs/' . $category->slug;
}
return $url;
});
相关挂钩
- post.frontend_url - 自定义帖子公共 URL
- theme.view.data - 将数据注入视图