Can anyone tell me the php code that would allow me to make a block visible only on the first page of a term page? I have a taxonomy term as my home page, using PathAuto for cleaner paths... so the home page path is http://mywebsite.com/headlines, with "headlines" as the taxonomy term, which has a pager at the bottom. The first page shows 6 node teasers, then it goes to page 2, 3, etc.

If I set a block to be visible on the of the site, I get the block visible on the headlines page, but I also get it visible on consecutive pages of that term.

I want the block visible on only these pages:
http://mywebsite.com/
http://mywebsite.com/headlines
http://mywebsite.com/headlines?page=0

I don't want it visible on these pages, which still includes:
http://mywebsite.com/headlines?page=1
http://mywebsite.com/headlines?page=2
...
http://mywebsite.com/headlines?page=697
etc...

Please... can anyone solve this?

Comments

nevets’s picture

How about

//  Check for  front page
if ( drupal_is_front_page() ) {
   return TRUE;
}
else if ( arg(0) == 'headlines'  ) {
   $page = $_GET['page'];
   if ( empty($page) || $page ==  0  ) {
     return TRUE;
   }
}

return FALSE;
gregarios’s picture

Assigned: gregarios » Unassigned
Status: Fixed » Active

Thanks for your code. I'd just come up with a similar solution:

<?php
  $uri_request_id = $_SERVER['REQUEST_URI'];
  $section = explode("/", $uri_request_id);
  if ($section[2] != '') { return FALSE; }
  if ($section[1] == 'headlines') { return TRUE; }
  elseif ($section[1] == ''){ return TRUE; }
  else { return FALSE; }
?>

Actually, since even headlines/?page=1 was qualifying as a <front> to the block, wouldn't your code return true just like <front> since it would never get past the first if?

Which is a better way?

gregarios’s picture

Assigned: Unassigned » gregarios
Status: Active » Fixed

My solution posted does seem to work in all tested circumstances. Fixed. :-)

Assigned: Unassigned » gregarios
Status: Active » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

artscientific’s picture

Thank you for this nevets, tried 3 other solutions that did not work before finding yours! BTW the other solution on this page did not work for me.