Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTagCloud: support filtering for taxonomy_id like in getPageTerms #21

Open
swbraun opened this issue Apr 8, 2015 · 1 comment
Open
Assignees

Comments

@swbraun
Copy link

swbraun commented Apr 8, 2015

I couldn't find a way to group the clouded terms by tags or categories since the filering by taxonomy_id was not possible. Maybe I was missing something, but for now I changed the snipped myself.
I attach the diff below. It would be nice, if this could be incorporated.

@swbraun
Copy link
Author

swbraun commented Apr 8, 2015

diff --git a/elements/snippets/getTagCloud.php b/elements/snippets/getTagCloud.php
index b85e61e..ca7c372 100644
--- a/elements/snippets/getTagCloud.php
+++ b/elements/snippets/getTagCloud.php
@@ -14,6 +14,7 @@
  * @param textfield $innerTpl Format the Inner Item of List
  * @param textfield $sort column: pagetitle, id, count
  * @param textfield $dir ASC | DESC default=DESC
+ * @param int $taxonomy_id limit terms to only this taxonomy 
  * @param numberfield $limit Limit the result, default to 10 : setting it to 0 will show all
  * @param combo-boolean $includeEmpty include all terms (disregard if it's assigned to certain page)
  *
@@ -40,6 +41,9 @@ $dir = $modx->getOption('dir',$scriptProperties, 'DESC');
 $outerTpl = $modx->getOption('outerTpl',$scriptProperties, '<ul>[[+content]]</ul>');
 $innerTpl = $modx->getOption('innerTpl',$scriptProperties, '<li><a href="[[~[[+id]]]]">[[+pagetitle]]</a> <strong>([[+count]])</strong></li>');

+$taxonomy_id = $modx->getOption('taxonomy_id',$scriptProperties,null);
+$and_where = (is_null($taxonomy_id)) ? '' : 'AND doc.parent = ' . $taxonomy_id;
+
 $content_table = $modx->getTableName('modResource');
 $pageterms_table = $modx->getTableName('PageTerm');
 if($includeEmpty == 1)
@@ -47,7 +51,7 @@ if($includeEmpty == 1)
        $sql = "SELECT doc.id as id, doc.pagetitle, count(terms.page_id) as count
                FROM $content_table doc
                LEFT JOIN $pageterms_table terms ON doc.id = terms.term_id
-               WHERE doc.class_key='Term'
+               WHERE doc.class_key='Term'  {$and_where}
                GROUP BY doc.id";
 }
 else
@@ -55,7 +59,7 @@ else
        $sql = "SELECT terms.term_id as id, doc.pagetitle, count(*) as count
                FROM $content_table doc
                JOIN $pageterms_table terms ON terms.term_id = doc.id
-               WHERE doc.class_key='Term'
+               WHERE doc.class_key='Term'  {$and_where}
                GROUP BY terms.term_id";
 }

@@ -72,4 +76,4 @@ if(count($results) == 0)
        $modx->log(\modX::LOG_LEVEL_DEBUG, "No results found",'','getTagCloud',__LINE__);
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants