TYPO3 通过 sys_categor(y/ies) 获取页面
TYPO3 get pages by sys_categor(y/ies)
我需要你的帮助,我只见树木不见森林。
考虑以下情况:
一个 TYPO3 - 系统有 2 个页面。 (关于我们和服务)
此外,我有 3 个系统类别(Cat 1、Cat 2 Cat 3)
关于我们的页面,类别 "Cat 1" 和 "Cat 2"。
页面服务有类别 "Cat 2" & "Cat 3".
现在我需要一个 SELECT 打字错误查询,从中我只能得到 "Cat 3" 和“Cat 2”的页面(在这种情况下,它将是页面服务)。
但让我们从简单的 SQL 而不是 Typoscript 查询开始。
对于这种情况,TYPO3 中存在以下 3 个表:
"pages"、"sys_category"、"sys_category_record_mm"
pages - table:
+-----+----------+------------+
| uid | title | categories |
+-----+----------+------------+
| 3 | About us | 2 |
| 4 | Services | 2 |
+-----+----------+------------+
sys_category - table:
+-----+-------+
| uid | title |
+-----+-------+
| 1 | Cat 1 |
| 2 | Cat 2 |
| 3 | Cat 3 |
+-----+-------+
sys_category_record_mm - table:
+-----------+-------------+------------+
| uid_local | uid_foreign | tablenames |
+-----------+-------------+------------+
| 2 | 4 | pages |
| 2 | 3 | pages |
| 1 | 4 | pages |
| 3 | 3 | pages |
+-----------+-------------+------------+
现在我有一个简单的 sql 查询,它输出所有获得类别的页面,如下所示:
SELECT DISTINCT title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
这将使我得到以下输出:
+----------+
| title |
+----------+
| Services |
| About us |
+----------+
但现在我只想拥有包含类别 "Cat 2" 和类别 "Cat 3" 的页面 "Services"。
如何修改我的查询以仅获取包含两个类别的页面。
我试过类似的方法,但我知道这行不通,因为 OR 条件我仍然会得到两个页面。
SELECT DISTINCT title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages' AND (sys_category_record_mm.uid_local = 2 OR sys_category_record_mm.uid_local = 3)
提前致谢!!
我很感谢你的每一个提示。
您必须使用 GROUP BY
将查询限制为具有特定 uid 的行,然后仅使用必须 select 组中符合您条件的那些行。
考虑以下几点:
SELECT DISTINCT pages.title, uid_local, uid_foreign FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
给出这个结果
+----------+-----------+-------------+
| title | uid_local | uid_foreign |
+----------+-----------+-------------+
| Services | 2 | 53 |
| Services | 3 | 53 |
| About Us | 1 | 54 |
| About Us | 2 | 54 |
+----------+-----------+-------------+
SELECT DISTINCT pages.title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
GROUP BY sys_category_record_mm.uid_local
HAVING sys_category_record_mm.uid_local = 2 or sys_category_record_mm.uid_local = 3
这给了我
+--------+
|Title |
+--------+
|Services|
+--------+
感谢 Marcus Schwemer,他为我指明了解决方案。
感谢pgampe的解答!
我已经用类别菜单完成了。
正如马库斯所说:"Each in the resulting array of pages gets an additional entry with key _categories containing the list of categories the page belongs to, as a comma-separated list of uid’s. It can be accessed with stdWrap.field or getText like any other field."
在菜单中执行 if 条件很容易,例如:
20 = HMENU
20 {
special = categories
# Show all pages with categories 1, 2 and 3
special.value = 1,2,3
1 = TMENU
1.NO {
# get comma-separated list of uid's of the categories the page belongs to
stdWrap.field = _categories
# check the _categories field if it contains the categories you need.
stdWrap.if {
value = 2,3
equals.field = _categories
}
}
}
就这些了...
我需要你的帮助,我只见树木不见森林。 考虑以下情况:
一个 TYPO3 - 系统有 2 个页面。 (关于我们和服务) 此外,我有 3 个系统类别(Cat 1、Cat 2 Cat 3)
关于我们的页面,类别 "Cat 1" 和 "Cat 2"。 页面服务有类别 "Cat 2" & "Cat 3".
现在我需要一个 SELECT 打字错误查询,从中我只能得到 "Cat 3" 和“Cat 2”的页面(在这种情况下,它将是页面服务)。
但让我们从简单的 SQL 而不是 Typoscript 查询开始。
对于这种情况,TYPO3 中存在以下 3 个表:
"pages"、"sys_category"、"sys_category_record_mm"
pages - table:
+-----+----------+------------+
| uid | title | categories |
+-----+----------+------------+
| 3 | About us | 2 |
| 4 | Services | 2 |
+-----+----------+------------+
sys_category - table:
+-----+-------+
| uid | title |
+-----+-------+
| 1 | Cat 1 |
| 2 | Cat 2 |
| 3 | Cat 3 |
+-----+-------+
sys_category_record_mm - table:
+-----------+-------------+------------+
| uid_local | uid_foreign | tablenames |
+-----------+-------------+------------+
| 2 | 4 | pages |
| 2 | 3 | pages |
| 1 | 4 | pages |
| 3 | 3 | pages |
+-----------+-------------+------------+
现在我有一个简单的 sql 查询,它输出所有获得类别的页面,如下所示:
SELECT DISTINCT title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
这将使我得到以下输出:
+----------+
| title |
+----------+
| Services |
| About us |
+----------+
但现在我只想拥有包含类别 "Cat 2" 和类别 "Cat 3" 的页面 "Services"。
如何修改我的查询以仅获取包含两个类别的页面。
我试过类似的方法,但我知道这行不通,因为 OR 条件我仍然会得到两个页面。
SELECT DISTINCT title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages' AND (sys_category_record_mm.uid_local = 2 OR sys_category_record_mm.uid_local = 3)
提前致谢!!
我很感谢你的每一个提示。
您必须使用 GROUP BY
将查询限制为具有特定 uid 的行,然后仅使用必须 select 组中符合您条件的那些行。
考虑以下几点:
SELECT DISTINCT pages.title, uid_local, uid_foreign FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
给出这个结果
+----------+-----------+-------------+
| title | uid_local | uid_foreign |
+----------+-----------+-------------+
| Services | 2 | 53 |
| Services | 3 | 53 |
| About Us | 1 | 54 |
| About Us | 2 | 54 |
+----------+-----------+-------------+
SELECT DISTINCT pages.title FROM pages
JOIN sys_category_record_mm ON sys_category_record_mm.uid_foreign = pages.uid
WHERE sys_category_record_mm.tablenames = 'pages'
GROUP BY sys_category_record_mm.uid_local
HAVING sys_category_record_mm.uid_local = 2 or sys_category_record_mm.uid_local = 3
这给了我
+--------+
|Title |
+--------+
|Services|
+--------+
感谢 Marcus Schwemer,他为我指明了解决方案。 感谢pgampe的解答!
我已经用类别菜单完成了。 正如马库斯所说:"Each in the resulting array of pages gets an additional entry with key _categories containing the list of categories the page belongs to, as a comma-separated list of uid’s. It can be accessed with stdWrap.field or getText like any other field."
在菜单中执行 if 条件很容易,例如:
20 = HMENU
20 {
special = categories
# Show all pages with categories 1, 2 and 3
special.value = 1,2,3
1 = TMENU
1.NO {
# get comma-separated list of uid's of the categories the page belongs to
stdWrap.field = _categories
# check the _categories field if it contains the categories you need.
stdWrap.if {
value = 2,3
equals.field = _categories
}
}
}
就这些了...