Shop By Brand /Manufacturer - Dropbox

Contrib type: 
Code/CSS Snippet
Status: 
Complete and working

Downloads


Compatibility: 
Ubercart 1.x

For Drupal 5.x

How to Setup!

1) Where it says $vid=1;, replace the number 1 with the vocabulary ID number for the vocabulary you want to use to populate the drop-down with the terms in that vocabulary.

2) Optional: Where it says $options[] = t('List by ' . $formname);, replace List by with the word(s) you want at the beginning of the default text in the drop-down.

3) Where it says $options['http://www.example.com/taxonomy/term/'.$term->tid] = $term->name;, replace example.com with the URL of your drupal website, or, leave only '/taxonomy/term/' to user relative path.

4) Put this PHP Code Snippet in a Block ---- Make sure you select PHP in the input format list for it to work.

<?php
$output
= drupal_get_form('Brands_dropdown_form', $form);
return
$output;

function

Brands_dropdown_form() {
$vid=1; //change to your Vocabulary ID
$formname="Brands";

$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
// Initialize the country array
$options[] = t('List by ' . $formname);
//Populate array with url / name
while ($term = db_fetch_object($vocabulary)) {
$options['/taxonomy/term/'.$term->tid] = $term->name;
}
//Build dropdown select
//If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
$form['category'] = array(
'#type' => 'select',
'#name' => $formname,
'#id' => $formname,
'#title' => '',
'#default_value' => '',
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);
return
$form;
}
?>

You can also use a basic Listing with this PHP Code

<?php
$vid
= 1; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid);
print
"<div class=\"item-list\">";
print
"<ul>";
foreach (
$terms as $term ) {
$tcount = taxonomy_term_count_nodes($term->tid);
print
"<li>".
l($term->name." (".$tcount.")",'taxonomy/term/'.$term->tid, array('title' => $tcount." posts in ".$term->name)).
"</li>";
}
/* end foreach */
print "</ul>";
print
"</div>";
?>
alien73's picture
Offline
Bug Finder
Joined: 11/10/2007
Juice: 450
Re: Shop By Brand /Manufacturer - Dropbox

If you want cleaner urls use this code snippet for the options above

$options['/taxonomy/term/'.$term->tid] = $term->name;

replace with

$options['http://www.example.com/' . str_replace(' ', '-', $term->name)] = $term->name;