Search

I was in need of something like this and found this old thread. Here is an updated version that works with Symphony 2.3.3:

<?php

    require_once(TOOLKIT . '/class.datasource.php');

    Class datasourcetags extends SectionDatasource {

        public $dsParamROOTELEMENT = 'tags';
        public $dsParamFIELDID = 123;

         public function about() {
            return array(
                'name' => 'Tags',
                'author' => array(
                    'name' => 'Büro für Web- und Textgestaltung',
                    'website' => 'http://hananils.de',
                    'email' => 'buero@hananils.de'),
                'version' => 'Symphony 2.3.3'
            );
        }

        public function execute(array &$param_pool = null) {
            $result = new XMLElement($this->dsParamROOTELEMENT);

            $tags = Symphony::Database()->fetch(sprintf("
                SELECT DISTINCT(handle), COUNT(handle) AS count, value 
                FROM sym_entries_data_%d 
                GROUP BY handle 
                ORDER BY handle ASC
            ", $this->dsParamFIELDID));

            if(empty($tags)) {
                return $this->emptyXMLSet();               
            }

            foreach($tags as $tag){
                $item = new XMLElement('tag', General::sanitize($tag['value']), array(
                    'handle' => $tag['handle'], 
                    'count' => $tag['count']
                ));
                $result->appendChild($item);
            }

            return $result;
        }
    }

?>

Wow, lucky me! Thanks @nickdunn and @Nils! This is exactly what I needed.

Hurrah! Just got this (mostly) working - I have a unique list of policy titles which link to the policies which are tagged with those titles! The number of instances doesn't seem to make any difference to the way the page looks, but I don't need it to.

Thanks!!!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details