Advertisement
dajare

Tags listing with tagged pages (Wolf CMS)

Apr 25th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. function allTags() {
  3.     global $__CMS_CONN__;
  4.     $sql = 'SELECT name FROM '.TABLE_PREFIX.'tag';
  5.     $arr = array();
  6.  
  7.     $stmt = $__CMS_CONN__->prepare($sql);
  8.     $stmt->execute();
  9.     while ($obj = $stmt->fetchObject())
  10.         array_push($arr, $obj->name);
  11.     return $arr;
  12. }
  13. print_r(allTags());
  14. // echo allTags();
  15. ?>
  16.  
  17. <?php foreach (allTags() as $tag) : ?>
  18.  
  19. <?php $findTag = $tag; // REPLACE hello WITH THE TAG YOU WANT TO FIND ?>
  20. <h3>Pages with the tag "<?php echo $findTag; ?>":</h3>
  21. <ul>
  22. <?php foreach ($this->find('articles')->children() as $child): ?>
  23. <?php $childTags = join(',', $child->tags()); ?>
  24.   <?php if (preg_match("/\b".$findTag."\b/i", $childTags)) : ?>
  25.     <li><?php echo $child->link(); ?></li>
  26.   <?php endif; ?>
  27. <?php endforeach; ?>
  28. </ul>
  29.  
  30. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement