A project I'm working on requires Categories across multiple Articles Containers, as well as 'global tag pages' that display tags across multiple Article Containers. I thought I'd share what I came up with. I'm not sure if it's the best way to go about this, but it seems to be working.
To create URLs like /categories/modx and /tags/snippets, I created a custom page to handle 404s by setting the error_page System Setting. On that page, I call this snippet [[!errorPage]].
$categoryURL = $modx->runSnippet('getCategoryByURL');
$tagURL = $modx->runSnippet('getTagsByURL');
if($categoryURL) {
return $modx->getChunk('feature-category-default',array('category' => $categoryURL));
}
if($tagURL) {
return $modx->getChunk('feature-tag-default',array('tag' => $tagURL));
}
return $modx->getChunk('error-page');
So I check for a category URL (/category/something) or a tag URL (/tags/something). If either is found, a call chunks and pass the category or tags slug to serve those pages appropriately. If neither is found, falls back to a default error-page chunk.
I'm using getResources &where and &tvFilters to pull from multiple Article Containers and filter the results. Now I'm not able to use any of the nifty Article features on these pages.
[[getResources?
&parents=`6,8,9`
&showHidden=`1`
&limit=`15`
&includeTVs=`1`
&processTVs=`1`
&tpl=`feature-all-item`
&tvFilters=`postCategory==[[+category]]`
]]
Here's what the URL sniffing snippets look like
$url = $modx->runSnippet('curPageURL');
$site_url = $modx->getOption('site_url');
$u = parse_url($url);
$folders = explode('/',$u['path']);
return ($folders[1] == 'categories') ? urldecode(array_pop($folders)) : '';
$url = $modx->runSnippet('curPageURL');
$site_url = $modx->getOption('site_url');
$u = parse_url($url);
$folders = explode('/',$u['path']);
return ($folders[1] == 'tags') ? urldecode(array_pop($folders)) : '';
[ed. note: dinocorn last edited this post 11 years, 8 months ago.]