Copied from main forum, may get more information here. I'm also willing to pay for help with this, it's important that it works correctly and I'm spending too much time trying to figure it out (20+hours)

Hi,
I have a site with multiple sections based on taxonomy terms. ie. Biology, Chemistry, Maths etc.

Is it possible to have a different node page for each one so that, for example, when I click on a link in the biology section, it is directed to the biology/node page?

My problem stems from resources (nodes) being available in more than one section. At the moment I have views setup with urls such as $arg/images where the $arg is the taxonomy term such as biology.

This works perfectly for displaying the list of nodes, please see http://www.whatdandidnext.co.uk/toolkit/biology/images .

When you click on a node title in that list the url is no longer at biology/ it just returns to /node/nid so the styles and menus don't remain. I need it to link through to a node page that keeps the biology style?

I can't use pathauto to assign a url at biology/ for the node because it could also appear in the chemistry section.

Comments

rernst’s picture

Someone else who knows more may correct me, but I just don't believe that Drupal is meant to function this way.

What have you tried already? Perhaps giving a brief overview here would help others

rizqi’s picture

hi ryan,

i help daniel make this thing work. I use custom_url_rewrite function to do this (http://api.drupal.org/api/function/custom_url_rewrite/5)

You can see the result on daniel website :
http://www.whatdandidnext.co.uk/toolkit/biology/images
http://www.whatdandidnext.co.uk/toolkit/mathematics/images
http://www.whatdandidnext.co.uk/toolkit/chemistry/images
http://www.whatdandidnext.co.uk/toolkit/physics/images

You can contact me for more information

Skype, Yahoo, Gtalk, AIM : xectra

Thanks
Rizqi
Surabaya, Indonesia

Hitby’s picture

Rizqi wrote some custom php code that went into the settings.php file which has fixed this problem. I will post it here but it will need some slight modification for use in your own projects.

Also, I can recommend Rizqi as a great developer to work with. Very reasonably priced and stayed up sorting out the problem with myself until 2am! He would be my first port of call should I need work doing in the future.

function custom_url_rewrite($op, $result, $path, $path_language = '') {

  global $user;

  $base_path = '/toolkit/';
  $q = $_SERVER['REQUEST_URI'];
  $q = str_replace($base_path,'',$q);
  $a = explode('/',$q);
  $term_name = $a[0];
  $special = array( // special case for path
    'computing' => 'IT & Computing',
    'geography' => 'Physical Geography',
    'physics' => 'Physics & Engineering'
  );    
  if (isset($special[$term_name])) {
      $term_name = $special[$term_name];
  }

    
  if ($op == 'alias') {
    if ($term = taxonomy_get_term_by_name($term_name)) {
      if (preg_match('|^node(/.*)|', $path, $matches)) {
        $nid = explode("/",$matches[1]);
        if (is_numeric($nid[1])) {
        $dbresult = db_fetch_object(db_query("select n.nid, n.type from {node} n where n.nid=%d and n.type IN ('image','lesson_pack','events','workshops','video')",$nid[1]));
        if ($dbresult->nid) {
        return $a[0].'/'.$a[1].'/node'. $matches[1];
        }
        }
        
      }
    }
    
  }
  
   if ($op == 'source') {
   
    if (!function_exists('taxonomy_get_term_by_name2')) {   
      function taxonomy_get_term_by_name2($name) {
        $db_result = db_query("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER('%s') LIKE LOWER(t.name)",trim($name));
        $b = array();
        while ($term = db_fetch_object($db_result)) {
          $b[] = $term;
        }

        return  $b;
      }
    }
    
    if ($term = taxonomy_get_term_by_name2($term_name)) {
				if (isset($a[0]) && isset($a[1])) {
      if (preg_match('|^'.$a[0].'/'.$a[1].'/node(/.*)|', $path, $matches)) {
        return 'node'.$matches[1];
      }
}
    }
   }
  // Do not forget to return $result!
  return $result;
}