2

I'd like to have a taxonomy drop-down list like the one in www.1mobile.com. Quick Links

When I select an term, it should go to the respective page, showing products concerning with selected term. I tried Custom Search module. But as far as I concern, it is not meet my requirement.

What is the best way to fulfill this requirement?

1

Try Autocomplete Deluxe, it has a taxonomy widget available for use, and I used it just the other day and I believe that it does what you need it to do.

1

Try Better Jump Menus. It does not have specific support for taxonomy but it has an api to do it via custom module. If you do not want to go the custom module way then have a look at Taxonomy menu can be used along to get the desired effect.

Other option would be Jump

1

I've chosen "custom module".

function my_module_block_info() {
    $blocks['quicklinks'] = array(
    'info' => t('Quick Links'),
    'cache' => DRUPAL_NO_CACHE
    );
    return $blocks;
}

function my_module_block_view($delta = '') {
$block = array(); # Declare array

switch ($delta) {
case 'quicklinks' : 
    $options = array(); // Options for category combo

    // Getting terms from vocabulary "Category" 
    $terms = my_module_taxonomy_get(4, 0); //echo '<pre>';print_r($terms);echo '</pre>';
    $options['c-all'] = t('Choose a Category');
    foreach ($terms as $term) {
        $options[$term->tid] = $term->name;
    }

    // Block View
    $block['subject'] = 'Quick Links';
    $block['content'] = array(
        'combo' => array(
            '#type'          => 'select',
            '#default_value' => 'c-all',
            '#options'       => $options,
            '#attributes'    => array(
                'id' => 'quick_links_select', 
                'class' => array('quick_links', 'select'), 
                'onchange' => 'my_module_browse_by_category()'
            ),
        ),
        'links1' => array(
            '#type' => 'markup',
            '#prefix' => '<div class="quick_links top link">',
            '#markup' => l('Future icons Apps', base_path() . 'ours'),
            '#suffix' => '</div>',
        ),
        'links2' => array(
            '#type' => 'markup',
            '#prefix' => '<div class="quick_links second link">',
            '#markup' => l("Editor's Choice", base_path() . 'editor'),
            '#suffix' => '</div>',
        ),
        'links3' => array(
            '#type' => 'markup',
            '#prefix' => '<div class="quick_links third link">',
            '#markup' => l('Apps Starter Kit', base_path() . 'appstarter'),
            '#suffix' => '</div>',
        ),
        'links4' => array(
            '#type' => 'markup',
            '#prefix' => '<div class="quick_links forth link">',
            '#markup' => l('Games Starter Kit', base_path() . 'gamestarter'),
            '#suffix' => '</div>',
        ),
    ); 
 }
 return $block;
}

function my_module_taxonomy_get($vid, $get_base_term = FALSE) {
  // Getteing Terms     
  $query = db_select('taxonomy_term_data', 't');
  $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
   $result = $query
    ->fields('t')
    ->condition('t.vid', $vid)
->condition('h.parent', 0, '!=')
    ->orderBy('t.name')
    ->execute();

  foreach ($result as $term) {
    $terms[] = $term;
  }

  return $terms;
}

With above code, I got what I want. But I don't understand much about $block['content'] thing and how ['content'] is rendered.

Is there any sources which fully explain how it works ?

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.