WEB PHP/Drupal crew, quick question..

Discussion in 'OT Technology' started by Insert Tokens, Jan 7, 2008.

  1. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,315
    Likes Received:
    70
    Location:
    Tasmania
    I'm making a template for a drupal site, for my shop.

    I want to do a condition in the template, so it ONLY shows a few certain images if the person is on the homepage..

    I have it in a dir now called /new/.. so i've done the following in my page.tpl.php:

    Code:
    <?php if ($_SERVER['REQUEST_URI'] == "/new/") { ?>
        <td id="content-right">
          <img src="/new/images/randoshop/halo3night.jpg">
        </td>
    <?php } ?>  
    But then if they go to /new/index.php it obviously doesn't work.

    Is there a better way to do this?
     
  2. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    Code:
    <?php if ($_SERVER['PHP_SELF'] == "/new/index.php") { ?>
        <td id="content-right">
          <img src="/new/images/randoshop/halo3night.jpg">
        </td>
    <?php } ?>  
     
  3. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,315
    Likes Received:
    70
    Location:
    Tasmania
    Then it won't work if there's no index.php in the title.

    Surely there's a better way than checking the URL in the first place, is my point. Is there a variable in Drupal templating that defines what page they're on?
     
  4. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    did you try it? the title doesn't affect PHP_SELF
     
  5. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,315
    Likes Received:
    70
    Location:
    Tasmania
    My bad sorry, thought you only changed the /new/ bit.. my brain is fried from trying to get this template done..

    Using your code, it now puts those pictures in every single page..
     
  6. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,315
    Likes Received:
    70
    Location:
    Tasmania
    Fixed it.. had previously downloaded a bunch of other templates to look through their code and learn, one was checking for $is_front .. so I just changed mine to do <?php if ($is_front == TRUE) { ?> and it works fine :)
     
  7. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    try

    Code:
    <?php if (!(isset($_REQUEST['q']))) { ?>
        <td id="content-right">
          <img src="/new/images/randoshop/halo3night.jpg">
        </td>
    <?php } ?>  
     
  8. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    ah, nm :)
     
  9. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,915
    Likes Received:
    8
    Location:
    Los Angeles
    It doesn't work because Drupal uses nodes and not paths.

    Try something like this

    Code:
    <?php if ($_GET['q'] == 'node/1') { ?>
      <td id="content-right">
        <img src="/new/images/randomshop/halo3night.jpg" />
      </td>
    <?php } ?>
    
    Make sure the path is correct. Usually images are placed in the files folder or theme images folder from your Drupal root.

    You can probably clean up your code a lot by using blocks in Drupal, and placing the random image in a block of its own, and displaying the block on a specific node.

    Then you'll end up with something like:
    Code:
    if ($_GET['q'] == 'node/1') {
      print $sidebar_right;
    }
    
     

Share This Page