Hello everyone. I have a game site that is built in PHP using smarty. I'm new to PHP and having problems editing it. I have some advertising I want to add but I want to only add it to a specific page. I can get it to go on the site but it adds it to every page.What do I need to add to the code to just get it to show on a particular page. Here is the line I added: <div>{include file="test.tpl"}</div> Code (markup): Somebody had mentioned to me that I need to add an "if" and the page url to the code so it would only add it if it was the page I wanted it on. Any help would be appreciated. thanks.
<?php if($_SERVER['SCRIPT_NAME'] == "/filename.php") { ?> <div>{include file="test.tpl"}</div> <?php } ?> PHP: change filename.php to whatever the name of the file is. You can see other ways of getting this here: http://blog.taragana.com/index.php/...erverscript_name-in-php-and-when-to-use-what/
thanks for your help. That didnt work for me either. I changed /filename.php to index.html which is the page I want it on and it didnt work.
Put this code in the spot you want it, then load the page. View Source it and copy everything you see here. Even if it's not the index page, you should see: <!-- BEGIN TEST: something.html --> <!-- END OF TEST --> <!-- BEGIN TEST: <?php echo $_SERVER['SCRIPT_NAME']; ?> --> <?php if($_SERVER['SCRIPT_NAME'] == "/filename.php") { ?> <div>{include file="test.tpl"}</div> <?php } ?> <!-- END OF TEST --> PHP:
Here is the code for the whole file. its trhe layout.tpl file I replaced the code and changed filename.php to /index.html and I get an error and the whole site quits working. The line of code is at the very bottom. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{$Site_Title}</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="keywords" content="{$Site_Keywords}"> <meta name="description" content="{$Site_Desc}"> <link rel="stylesheet" type="text/css" media="screen" href="{$T_CSS_Tpl}default.css" /> <link rel="stylesheet" type="text/css" media="screen" href="{$T_CSS_Tpl}arcade.css" /> <link rel="stylesheet" type="text/css" media="screen" href="{$T_CSS_Tpl}global.css" /> <script type="text/javascript" src="{$T_JS}jquery/jquery.js"></script> <script type="text/javascript" src="{$T_JS}jquery/jtip2.js"></script> <script type="text/javascript" src="{$T_JS}functions.js"></script> {section name=FileName loop=$JavaScript} <script type="text/javascript" src="{$T_JS_Tpl}{$JavaScript[FileName]}"></script> {/section} </head> <body style="body"> <div style="margin: 0 auto;width:990px;padding:0;" class="box1"> <div>{include file="header.tpl"} </div> <div>{include file="top_menu.tpl"}</div> <div><script type="text/javascript"><!-- google_ad_client = "pub-----------"; /* 728x15, created 6/14/08 */ google_ad_slot = "---------"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div> <div>{include file="last_played_games.tpl"}</div> <div style="float:left;width:170px;padding:5px 0px 5px 5px;">{include file="left_v_menu.tpl"}</div> <div style="float:left;width:630px;padding:5px 0px 5px 5px;">{include file="$T_Body"}</div> <div style="float:right;width:170px;padding:5px 0px 5px 5px;">{include file="right_v_menu.tpl"}</div> <div style="float:none;clear:both;"></div> <div>{include file="test.tpl"}</div <div>{include file="footer.tpl"}</div> </div> </body> </html> Code (markup):
I can't figure out why the code I sent you doesn't work. I suspect it's because you are using PearPHP instead of just standard PHP. So here's an alternative suggestion - get Open Ads. It's an open source ad program that will manage this crap for you (http://www.openads.org) or use Google Ad Manager, which is now available to anybody. That'll save you trying to fiddle with the code.