Last active
October 8, 2024 16:56
-
-
Save matdave/1ab01922d3997b4e90195296cbdccf6f to your computer and use it in GitHub Desktop.
MODX count number of times a template is used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.id AS 'ID', | |
CASE | |
WHEN a.menutitle = '' THEN a.pagetitle | |
ELSE a.menutitle | |
END AS 'Title', | |
a.uri AS 'URI', | |
c.templatename AS 'Template', | |
CASE | |
WHEN a.hidemenu = 1 THEN 'Hidden' | |
ELSE 'Visible' | |
END AS 'Visibility', | |
COUNT(b.id) AS 'Immediate Children' | |
FROM modx_site_content a | |
LEFT JOIN modx_site_content b ON a.id = b.parent AND b.published = 1 AND b.deleted = 0 | |
LEFT JOIN modx_site_templates c ON a.template = c.id | |
WHERE a.published = 1 AND a.deleted = 0 AND a.parent = 0 | |
GROUP BY a.id, a.menuindex | |
ORDER BY a.menuindex ASC; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.id, a.templatename, COUNT(b.id) as resources FROM modx_site_templates AS a | |
LEFT JOIN modx_site_content AS b ON a.id = b.template AND b.published = 1 AND b.deleted = 0 | |
WHERE b.id IS NOT NULL | |
GROUP BY a.id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.id, a.type, a.name, COUNT(c.id) FROM modx_site_tmplvars a | |
LEFT JOIN modx_site_tmplvar_contentvalues b ON a.id = b.tmplvarid | |
LEFT JOIN modx_site_content c ON b.contentid = c.id AND c.published = 1 AND c.deleted = 0 | |
WHERE c.id IS NOT NULL | |
GROUP BY a.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment