Skip to main content
added 28 characters in body
Source Link
xurshid29
  • 2.5k
  • 15
  • 13

Dylan Tack's answer is the right and the easiest way to achieve this functionality; My approach isIf you don't want to use Views module you can solve this by custom module, like this (I didn't test it, correct it, if something is wrong with it):

Dylan Tack's answer is the right and the easiest way to achieve this functionality; My approach is to solve this by custom module, like this (I didn't test it, correct it, if something is wrong with it):

Dylan Tack's answer is the right and the easiest way to achieve this functionality; If you don't want to use Views module you can solve this by custom module, like this (I didn't test it, correct it, if something is wrong with it):

Source Link
xurshid29
  • 2.5k
  • 15
  • 13

Dylan Tack's answer is the right and the easiest way to achieve this functionality; My approach is to solve this by custom module, like this (I didn't test it, correct it, if something is wrong with it):

function myModule_menu() {
  $items = array();

  $items['jobs/%taxonomy_term'] = array(
    'title' => 'Jobs',
    'page callback' => 'custom_page_by_jobs',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  $items['companies/%taxonomy_term'] = array(
    'title' => 'Companies',
    'page callback' => 'custom_page_by_companies',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

// Mimic of taxonomy_select_nodes() function;
function taxonomy_select_nodes_by_type($tid, $type, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC')) {
  if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
    return array();
  }
  $query = db_select('taxonomy_index', 't');
  $query->join('field_data_field_city', 'fdfc', 't.tid = fdfc.field_city_tid');
  $query->addTag('node_access');
  $query->condition('t.tid', $tid);
  $query->condition('fdfc.bundle', $type, '=');
  if ($pager) {
    $count_query = clone $query;
    $count_query->addExpression('COUNT(t.nid)');

    $query = $query->extend('PagerDefault');
    if ($limit !== FALSE) {
      $query = $query->limit($limit);
    }
    $query->setCountQuery($count_query);
  }
  else {
    if ($limit !== FALSE) {
      $query->range(0, $limit);
    }
  }
  $query->addField('t', 'nid');
  $query->addField('t', 'tid');
  foreach ($order as $field => $direction) {
    $query->orderBy($field, $direction);
    list($table_alias, $name) = explode('.', $field);
    $query->addField($table_alias, $name);
  }
  return $query->execute()->fetchCol();
}


function custom_page_by_type($term, $type) {
//  drupal_set_title($term->name);
//
//  $current = (object) array(
//    'tid' => $term->tid,
//  );
//
//  $breadcrumb = array();
//  while ($parents = taxonomy_get_parents($current->tid)) {
//    $current = array_shift($parents);
//    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
//  }
//  $breadcrumb[] = l(t('Home'), NULL);
//  $breadcrumb = array_reverse($breadcrumb);
//  drupal_set_breadcrumb($breadcrumb);
//
//  $uri = entity_uri('taxonomy_term', $term);
//  drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
//
//  drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);

  $build['term_heading'] = array(
    '#prefix' => '<div class="term-listing-heading">',
    '#suffix' => '</div>',
    'term' => taxonomy_term_view($term, 'full'),
  );

  if ($nids = taxonomy_select_nodes_by_type($term->tid, $type, TRUE, 20)) {
    $nodes = node_load_multiple($nids);
    $build += node_view_multiple($nodes);
    $build['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 5,
    );
  }
  else {
    $build['no_content'] = array(
      '#prefix' => '<p>',
      '#markup' => t('There is currently no content classified with this term.'),
      '#suffix' => '</p>',
    );
  }
  return $build;
}


function custom_page_by_jobs($taxonomy_term) {
  return custom_page_by_type($taxonomy_term, 'jobs');
}

function custom_page_by_companies($taxonomy_term) {
  return custom_page_by_type($taxonomy_term, 'companies');
}