Drupal: Taxonomy tree with image

×

Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseCondition::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 1652 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property MergeQuery::$condition is deprecated in MergeQuery->__construct() (line 1344 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).

This CodeLet creates a tiled dispay of taxonomy block with child terms. If you use taxonomy image module, you can select the preset and taxonomy on block configuration page. The CodeLet then fetches all the tree along with their images and display in tile in the block.

Drupal: Taxonomy tree with image | Drupal Developer
CodeLet: 

<?php

/**
* @file
*
* Display taxonomy tree in a block
*
* @author DrupalD
*/

/**
* Implementation of hook_block
*
* @param $op
* @param $delta
* @param $edit
* @return unknown_type
* @author DrupalD
*/
function browse_info_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[1] = array(
'info' => t("Browse information by category"),
'status' => 1,
'region' => 'content',
'weight' => 0,
);

return $blocks;
case 'configure':
$am__vocabulary = _get_vocabulary();
$am__imagecache = _get_imagecache();

$form['browse_vocabulary'] = array(
'#type' => 'select',
'#title' => t("Vocabulary"),
'#options' => $am__vocabulary,
'#default_value' => variable_get('browse_vocabulary_id', ''),
);
$form['imagecahce'] = array(
'#type' => 'select',
'#title' => t("Image size"),
'#options' => $am__imagecache,
'#default_value' => variable_get('imagecache_size', ''),
);
$form['image_size'] = array(
'#type' => 'textfield',
'#title' => t("Image size"),
'#size' => 30,
'#description' => t("Provide image size in WXH format.
This value will be ignored if a size already selected from above ImageCache presets."),
'#default_value' => variable_get('image_size', ''),
);
return $form;
case 'save':
switch ($delta) {
case 1:
variable_set('browse_vocabulary_id', $edit['browse_vocabulary']);
variable_set('imagecache_size', $edit['imagecahce']);
variable_set('image_size', $edit['image_size']);
break;
}
break;
case 'view':
switch ($delta) {
case 1:
$block = array('subject' => t("Browse information by category"), 'content' => get_category_tree());
break;
}
return $block;
}
}

/**
* get_category_tree
*
* Return the tree stucture
*
* @return unknown_type
* @author DrupalD
*/
function get_category_tree() {
global $conf;
$sn__vid = variable_get("browse_vocabulary_id", '');
$am__term_tree = array();
if (!$sn__vid) {
drupal_set_message("You need to select a vocabulary for the block.");
}
else {
$am__tree = taxonomy_get_tree($sn__vid, $parent = 0, $depth = -1, $max_depth = 2);
foreach ($am__tree as $om__term) {
if ($om__term->parents[0]) {
$am__term_tree[$om__term->parents[0]][] = $om__term->tid;
}
}
$ss__imagecache = variable_get('imagecache_size', '');
$ss__image_size = variable_get('image_size', '');
if (empty($ss__imagecache)) {
list($width, $height) = explode("X", $ss__image_size, -1);
$am__attribute = array('width' => $width, 'height' => $height);
}

$output .= "
";
$i = 0;
$k = 1;
foreach ($am__term_tree as $key => $an__child) {
$j = 0;
if($key) {
if ($i == 4) {
$output .= ($key ? "
" : NULL);
$i = 0;
}
unset($om__term);
$ss__image = db_result(db_query("SELECT path FROM {term_image} WHERE tid = %d", $key));
$om__term = taxonomy_get_term($key);
if ($ss__imagecache) {
$ss__imagcache_name = db_result(db_query("SELECT presetname FROM
{imagecache_preset} WHERE presetid = %d", $ss__imagecache));

$output .= "". theme('imagecache', $ss__imagcache_name,
variable_get('taxonomy_image_path', 'category_pictures') ."/". $ss__image) ."";
}
else {
$output .= "". theme('image',
variable_get('taxonomy_image_path', 'category_pictures')
."/". $ss__image, '', $am__attribute, FALSE) ."";
}
$i++;
$output .= "". l($om__term->name,
drupal_get_path_alias("taxonomy/term/". $om__term->tid)) ."";
$output .= "

    ";
    foreach ($an__child as $value) {
    if ($j == 3) {
    $output .= "

".
l(t("More") ."...", drupal_get_path_alias("taxonomy/term/".
$om__term->tid)) ."";
break;
}
else {
$om__child_term = taxonomy_get_term($value);
$output .= "

  • ". l($om__child_term->name,
    drupal_get_path_alias('taxonomy/term/'. $om__child_term->tid))
    ."
  • ";
    $j++;
    }

    }
    $output .= "

    ";
    $output .= (($i < 4 && !empty($an__child)) ?
    "" : NULL);
    }
    }
    $output .= "";
    $output .= "&nbsp";
    return $output;
    }
    }

    /**
    * _get_vocabulary
    *
    * Helper function. Return list of vocabularies
    * @return unknown_type
    * @author DrupalD
    */
    function _get_vocabulary() {
    $r__result = db_query("SELECT vid, name FROM {vocabulary}");
    while($om__result = db_fetch_object($r__result)) {
    $am__vocabulary[$om__result->vid] = $om__result->name;
    }
    return $am__vocabulary;
    }

    /**
    * _get_imagecache
    *
    * Return the imagecache preset
    *
    * @return unknown_type
    * @author DrupalD
    */
    function _get_imagecache() {
    $r__result = db_query("SELECT * FROM {imagecache_preset}");
    $am__preset[''] = t("Select");
    while ($om__result = db_fetch_object($r__result)) {
    $am__preset[$om__result->presetid] = $om__result->presetname;
    }
    return $am__preset;
    }
    ?>

    Compatibility: 
    Is CodeLet useful?: 
    Drupal: Taxonomy tree with image | Drupal Developer

    Error

    The website encountered an unexpected error. Please try again later.