0

I have a module that creates a list of taxonomy terms. This is the module.

    function theme_jl_custom_category_list($vars) {
      $items = array();
      foreach (taxonomy_get_tree($vars['vid']) as $term) {
        $attributes = array();

       $query = new EntityFieldQuery;
       $query->entityCondition('entity_type', 'node')
         ->fieldCondition('taxonomy_catalog', 'tid', $term->tid);

       if ($result = $query->execute()) {
         $nids = array_keys($result['node']);
       }
       if (isset($_GET['category']) && $_GET['category'] == $term->tid && $_GET['q'] == 'list-product') {
         $attributes['class'] = array('active-category');
       }

       /** How can I append &product=[$nid][0] to this? **/
       $items[] = l($term->name, 'list-product', array('query' => array('category' => $term->tid), 'attributes' => $attributes));
      }

      return theme('item_list', array('items' => $items, 'attributes' => array('class' => array('jl-custom-category-list'))));
    }

In my template.php file, I have the following code.

function [THEME]_preprocess_page(&$vars) {
  $vars['category_list'] = theme('jl_custom_category_list', array('vid' => 3));
  // …
}

In my page.tpl.php file I display the list with the following code.

<?php print ($category_list);  ?>

Combined, they create a list of links like the following ones:

I'm trying to modify these two pieces of code so that in the URL of each category I can append something like '&product=(ID OF FIRST NODE IN EACH CATEGORY)' in the URL to change the links to the following ones:

How can I modify the URL created by that module?

0

These are just hints to help yourself:

  • Take the Theme developer module, and check what functions are involved in putting the URL together.
  • Set a break point inside the l() function just before theme('jl_custom_category_list', array('vid' => 3)) gets executed. The stack should show you the code building the URL.
  • Well I know WHERE the url is created. My problem is that I don't know how to add my variable to it as to append "products=[node id]" to it. This line: $items[] = l($term->name, 'list-product', array('query' => array('category' => $term->tid), 'attributes' => $attributes)); seems to be what creates the url. – Digital fire Jul 10 '12 at 15:42
  • Great. It would be helpfull to let us know where this is (file, function, line, version of the module/core, maybe a copy of the fuction or a link to api.drupal.org, ... ). – BetaRide Jul 10 '12 at 15:46
  • I posted ALL the code in the question. – Digital fire Jul 10 '12 at 16:07
0

I was able to append the url with "product=" + first node id of the taxonomy term by modifying the line show in bold below.

// Before
$items[] = l($term->name, 'list-product', array('query' => array('category' => $term->tid), 'attributes' => $attributes));

// After
$items[] = l($term->name, 'list-product', array('query' => array('category' => $term->tid, 'product' => $nids[0]), 'attributes' => $attributes));

I assume Drupal creates the query string with array('query' => array('variable' => "whatever")).

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