So I'd like to redirect taxonomy term page or show the full content of the node on taxonomy page if there's only one node associated with that term.
- Hey Sohail,I come back stackexchange ,again see you with hard questions boy :D . hard question need bounty :DYuseferi– Yuseferi2016-06-18 08:59:11 +00:00Commented Jun 18, 2016 at 8:59
- Welcome back bro! :D I'll give you 500 bounty since you just asked :DSohail– Sohail2016-06-20 09:22:32 +00:00Commented Jun 20, 2016 at 9:22
- 1Tnx Dear, your questions often are particular that need exclusive answers ;)Yuseferi– Yuseferi2016-06-20 09:35:47 +00:00Commented Jun 20, 2016 at 9:35
Add a comment |
1 Answer
My solution is handle it in hook_preprocess_page(maybe there is another or better solutions but this is good too)
put this in template.php
first solution(maybe not worked)
function YOURTEMPLATE_preprocess_page(&$variables) { if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { $tid = arg(2); $items = taxonomy_select_nodes($tid; if(count($item)==1){ drupal_goto('node/'.$items[0]->nid); } } } Alternative solution
function YOURTEMPLATE_preprocess_page(&$variables) { if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { $tid = arg(2); $items = taxonomy_select_nodes($tid); if(count($items)==1){ //another solution is set a variable in preprocess and in page.tpl.php or your taxonomy tempalte page redirect it $variables['soheil_redirect_tax'] = array('path' => url('node/'.$items['nid'])); } } if first solution (drupal_goto) not worked in page.tpl.php or your custom template for terms page handle redirect(I mean in page.tpl.php file or taxonomy--term.tpl.php file) with
if(isset($soheil_redirect_tax)){ drupal_goto($soheil_redirect_tax['path']); } - Thanks a lot Yusof, I'll take a look into your solution and let you knowSohail– Sohail2016-06-20 09:33:48 +00:00Commented Jun 20, 2016 at 9:33
- @Sohail You're welcome,Ok ;)Yuseferi– Yuseferi2016-06-20 09:36:41 +00:00Commented Jun 20, 2016 at 9:36
- Hey Yusef, it almost worked with the second approach, it does redirect when there's only 1 taxonomy term on the page, but on my localhost it redirects to
~sohail/helger/~sohail/helger/node/, as you can see it repeats the base url and does not load thenidof the node to redirect it toSohail– Sohail2016-06-29 03:01:34 +00:00Commented Jun 29, 2016 at 3:01 - @Sohail try to
dsm($items)to see what you have there,maybe its a array then you have to replace it with$items[0]['nid'].Yuseferi– Yuseferi2016-06-29 07:07:50 +00:00Commented Jun 29, 2016 at 7:07 - it still doesn't work with
$items[0]['nid'], and unfortunatelydsm($items)is empty, I wonder if we can access nodes associated with terms like thisSohail– Sohail2016-07-02 02:25:55 +00:00Commented Jul 2, 2016 at 2:25