Advertisement
dajare

Find/Sort ALL tags (Wolf CMS)

Sep 18th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. /*
  3. This page looks through each page of the Articles branch, and groups its pages under shared tags.
  4. No plugin required.
  5. It also just happens to sort alphabetically on the tag, but I didn't ask it to!
  6. */
  7.  
  8. function allTags() {
  9.     global $__CMS_CONN__;
  10.     $sql = 'SELECT name FROM '.TABLE_PREFIX.'tag';
  11.     $arr = array();
  12.  
  13.     $stmt = $__CMS_CONN__->prepare($sql);
  14.     $stmt->execute();
  15.     while ($obj = $stmt->fetchObject())
  16.         array_push($arr, $obj->name);
  17.     return $arr;
  18. }
  19. /** / echo '<pre>'; print_r(allTags()); echo '</pre>'; /**/
  20. ?>
  21.  
  22. <?php $branchTags = array(); // define where you want tag-search to start
  23. foreach ($this->find('articles')->children() as $child) {
  24.     foreach ($child->tags() as $ctag) { array_push($branchTags, $ctag); }
  25. }
  26. // print_r($branchTags); ?>
  27.  
  28. <?php foreach (allTags() as $tag) : ?>
  29. <?php if (in_array($tag, $branchTags)) : // check to see if tag is in this branch... ?>
  30.  
  31. <?php $findTag = $tag; // looping all tags in tag table... ?>
  32. <h3>Pages with the tag "<?php echo $findTag; ?>":</h3>
  33. <?php foreach ($this->find('articles')->children() as $child): ?>
  34. <?php $childTags = join(',', $child->tags()); ?>
  35. <ul>
  36.   <?php if (preg_match("/\b".$findTag."\b/i", $childTags)) : ?>
  37.     <li><?php echo $child->link(); ?></li>
  38.   <?php endif; ?>
  39. </ul>
  40. <?php endforeach; ?>
  41.  
  42. <?php endif; endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement