Include template in php code of Wordpress - Help needed

Discussion in 'PHP' started by balkanboy82, Feb 5, 2010.

  1. #1
    I have code made in php to display different ads for Google visitors and all the rest. I need "echo" command for non-Google visitors replaced with "include" if possible with relative-not absoulte path.

    This is full code:

    <?php 
    	
    
    function getDomain($url)	{
    
    	if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE)
    		{
    			return false;
    		}
    
    	$parts = parse_url($url);
    
    	return $parts['host'];
    }
    
    	
    	$url = $_SERVER['HTTP_REFERER']; 
    
    	$raw_url=getDomain($url);
    
    	$domain_only =str_replace ('www.','', $raw_url); 
    	
    	if($url!=""){	
    		if($domain_only == "google.com")	{
    		
    		echo " ads for google visitors";
    		
    		}
    
    	}
    	else {
    			
    			echo "ads for non google visitors";
    			
    		}
    ?>
    PHP:
    I need this part:

    	else {
    			
    			echo "ads for non google visitors";
    			
    		}
    PHP:
    replaced with include function.
    I want to include nongoogle.php from Wordpress theme folder with relative path if possible.

    This is how it looks in regular wp language:

    <?php include (TEMPLATEPATH . '/adsensetop.php'); ?>
    PHP:
    I can't get it to work - tried many combinations.

    Help would be appreciated. If you like I can send 2$ by paypal for working code :)
    Thanks
     
    balkanboy82, Feb 5, 2010 IP
  2. balkanboy82

    balkanboy82 Well-Known Member

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Problem solved, thanks for looking.
     
    balkanboy82, Feb 5, 2010 IP
  3. DEWebDev

    DEWebDev Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'll try and help you out. The first thing you need to know is the folder that you need to upload "nongoogle.php" to. If you're not sure what folder it is, add this code to your wordpress index.php file, or whichever file you want the non-google ads to appear on, and then visit your site to see the absolute path:

    echo TEMPLATEPATH;
    PHP:
    That should give you the absolute path to your file. You should see something like "/home/username/public_html/domainname/wp-content/themes/themename". Upload "nongoogle.php" to the themename folder, and then replace " echo "ads for non google visitors";", with:

    include ('nongoogle.php');
    PHP:
    Save it and visit your site. I think that should do the trick for you.
     
    DEWebDev, Feb 5, 2010 IP
  4. balkanboy82

    balkanboy82 Well-Known Member

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Thanks a lot for help, appreciate it.

    Function wasn't good, it didn't work with echo too.

    include (TEMPLATEPATH . '/nongoogle.php');
    PHP:
    was ok for template path and works now when function is edited.

    Thanks again
     
    balkanboy82, Feb 5, 2010 IP