Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This page looks through each page of the Articles branch, and groups its pages under shared tags.
- No plugin required.
- It also just happens to sort alphabetically on the tag, but I didn't ask it to!
- */
- function allTags() {
- global $__CMS_CONN__;
- $sql = 'SELECT name FROM '.TABLE_PREFIX.'tag';
- $arr = array();
- $stmt = $__CMS_CONN__->prepare($sql);
- $stmt->execute();
- while ($obj = $stmt->fetchObject())
- array_push($arr, $obj->name);
- return $arr;
- }
- /** / echo '<pre>'; print_r(allTags()); echo '</pre>'; /**/
- ?>
- <?php $branchTags = array(); // define where you want tag-search to start
- foreach ($this->find('articles')->children() as $child) {
- foreach ($child->tags() as $ctag) { array_push($branchTags, $ctag); }
- }
- // print_r($branchTags); ?>
- <?php foreach (allTags() as $tag) : ?>
- <?php if (in_array($tag, $branchTags)) : // check to see if tag is in this branch... ?>
- <?php $findTag = $tag; // looping all tags in tag table... ?>
- <h3>Pages with the tag "<?php echo $findTag; ?>":</h3>
- <?php foreach ($this->find('articles')->children() as $child): ?>
- <?php $childTags = join(',', $child->tags()); ?>
- <ul>
- <?php if (preg_match("/\b".$findTag."\b/i", $childTags)) : ?>
- <li><?php echo $child->link(); ?></li>
- <?php endif; ?>
- </ul>
- <?php endforeach; ?>
- <?php endif; endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement