1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need help with php code

Discussion in 'PHP' started by indyonline, Jul 31, 2008.

  1. #1
    Hello everyone. I have a site that is in php and I'm using this code-
    <div>{include file="test.tpl"}</div>
    to add stuff in the page. I was wondering if there was a way to only add this to the index page? When I add it to the layout.tpl file it's on every page and I only want it on the index page. I would appreciate any help. Thanks in advance.
    SEMrush
     
    indyonline, Jul 31, 2008 IP
    SEMrush
  2. jack_ss

    jack_ss Guest

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this..
    {if $_SERVER[SCRIPT_NAME] == "/index.php"}
        <div>{include file="test.tpl"}</div>
    {/if}
    Code (markup):
     
    jack_ss, Jul 31, 2008 IP
  3. Web1Host

    Web1Host Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The issue isn't in your code or php but that you're using some kind of template system to build multiple pages.

    You can leave that out of your template and use a regular php 'include' statement in your finished index page, something like:

    <? include ("test.php");?>

    (I suspect a ".tpl" file is some sort of template rather than an html or php file?)
     
    Web1Host, Jul 31, 2008 IP
    GRIM likes this.
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    if(strpos(SERVER['PHP_SELF'],'index.php') === true){
    
      include 'test.tpl';
    
    }
    PHP:
     
    php-lover, Jul 31, 2008 IP
  5. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    For the above, did you even read the OP? Anyway, that wouldn't work in the situation where assumed, something like this would:
    if(strpos($_SERVER['PHP_SELF'], 'index.php') == true){
    
      include('test.tpl');
    
    }
    Code (markup):
     
    chopsticks, Jul 31, 2008 IP
  6. indyonline

    indyonline Prominent Member

    Messages:
    4,626
    Likes Received:
    248
    Best Answers:
    2
    Trophy Points:
    335
    #6
    Thank you all for your help. I have tried everyone's info and none have worked so far.
    Chopsticks, would that code go in between the divide tags? And in that code it uses- 'test.tpl' - Should it be "test.tpl" with the quotation marks instead?
     
    indyonline, Jul 31, 2008 IP
  7. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #7
    I assume you are using Smarty?

    Looking at the second reply you can change it to be this instead. I'm not to sure how everything actually works in Smarty and prefer not using it, lol.

    {if $_SERVER['PHP_SELF'] == "/index.php"}
        <div>{include file="test.tpl"}</div>
    {/if}
    Code (markup):
     
    chopsticks, Jul 31, 2008 IP
    indyonline likes this.
  8. indyonline

    indyonline Prominent Member

    Messages:
    4,626
    Likes Received:
    248
    Best Answers:
    2
    Trophy Points:
    335
    #8
    I'm not sure what I'm using. The site is a script I purchased from somebody. I tried the code that way and still no luck.
     
    indyonline, Jul 31, 2008 IP
  9. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Go to the library where your template parser is and check the headers of the file. If docummented they should state the name of the template parser that you are using.
     
    chopsticks, Jul 31, 2008 IP
  10. indyonline

    indyonline Prominent Member

    Messages:
    4,626
    Likes Received:
    248
    Best Answers:
    2
    Trophy Points:
    335
    #10
    Ya, It's smarty. Would it help if I posted the code?
     
    indyonline, Jul 31, 2008 IP
  11. almondj

    almondj Peon

    Messages:
    769
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #11
    Probably the index.php page and .tpl.
     
    almondj, Jul 31, 2008 IP