In D6, I have the page url of mypage.com/catalog/16?page=0%2C1 I have the following snipped in the pages section of a block, with the PHP snippet option chosen: <?php if ($_GET['q']) { $my_drupal_path = $_GET['q']; } else { $my_drupal_path = substr($_SERVER['REQUEST_URI'], 1); } if ( stristr($my_drupal_path, 'catalog/16?page=0%2C0') || ((stristr($my_drupal_path, 'catalog/16')) && (stristr($my_drupal_path, 'catalog/16?page')===false)) ) return true; else return false; ?> So the idea is that it will be TRUE for /catalog/16 and for /catalog/16?page=02C0 but not for page=02C1 or greater When I put the three parts of the if statement (separating both sides of the && into two statements) in a separate php file and test each, based on the given URL, the result is FALSE, TRUE, FALSE, which is what it should be. That said, the block continues to show on every page. If I force it to FALSE (comment the IF and just leave return false) the block does not show. I need another pair of eyes...mine are crossed at this point.
Jeff Greenberg wrote:
In D6, I have the page url of mypage.com/catalog/16?page=0%2C1
I have the following snipped in the pages section of a block, with the PHP snippet option chosen:
<?php if ($_GET['q']) { $my_drupal_path = $_GET['q']; } else { $my_drupal_path = substr($_SERVER['REQUEST_URI'], 1); }
if ( stristr($my_drupal_path, 'catalog/16?page=0%2C0') || ((stristr($my_drupal_path, 'catalog/16')) && (stristr($my_drupal_path, 'catalog/16?page')===false)) ) return true; else return false; ?>
Check $_GET['page'] for that part, rather than checking the request uri.
Earl Miles wrote:
Check $_GET['page'] for that part, rather than checking the request uri.
Hi Earl. I started with $_GE['page'], but the question (in my own sleep-deprived mind) arose, how do I get it to show only on page 1 of THAT page, as opposed to page 1 of another view? I first tried to use $nid and drupal_get_path_alias, but it appears that $nid is not exposed at this point.
try something like: if ($_GET['q'] == catalog/16 && $_GET['page'] == '0,0') { // do stuff } Note that the $_GET variable is automatically decoding special characters in the url. "%2C" is in fact an encoded comma, so check for $_GET['page'] == '0,0', not $_GET['page'] == '0%2C0'. Marc Jeff Greenberg wrote:
Earl Miles wrote:
Check $_GET['page'] for that part, rather than checking the request uri.
Hi Earl. I started with $_GE['page'], but the question (in my own sleep-deprived mind) arose, how do I get it to show only on page 1 of THAT page, as opposed to page 1 of another view? I first tried to use $nid and drupal_get_path_alias, but it appears that $nid is not exposed at this point.
Jeff Greenberg wrote:
Earl Miles wrote:
Check $_GET['page'] for that part, rather than checking the request uri.
Hi Earl. I started with $_GE['page'], but the question (in my own sleep-deprived mind) arose, how do I get it to show only on page 1 of THAT page, as opposed to page 1 of another view? I first tried to use $nid and drupal_get_path_alias, but it appears that $nid is not exposed at this point.
It's hard to answer this without knowing a little more about the path. Let me tell youwhat I know, though: $_GET['q'] will contain the internal URL that was called. i.e, if using pathauto, and you've got path/to/some/node, $_GET['q'] will still contain node/21 assuming that's the nid. If you're looking at an unaliased page, $_GET['q'] will contain the base URL. Another issue is that the page query string won't always be set. So you have a couple of possibilities here: $_GET['page'] could be empty. In this case, it's the same as '0,0'. $_GET['page'] could contain a value. In this case it should contain all page numbers (the 0,0 indicates you've got multiple pagers on the same page, which sucks =) SO check $_GET['q'] against 'catalog/16' and $_GET['page'] against empty or '0,0'
Thank you Earl and Marc, I've now replaced the klunky test with: return ( $_GET['q']=='catalog/16' && (empty($_GET['page']) || $_GET['page']=='0,0') ); and it works like a charm!
participants (3)
-
Earl Miles -
Jeff Greenberg -
Vangend