Solved

include file not working

Posted on 2011-09-05
10
428 Views
Last Modified: 2012-05-12
I want to add an include file to my wordpress header, but it's not showing.

Code below:

<?php include("/templates/header2.tpl"); ?>

The path is correct. Any idea's why it is not showing?
0
Comment
Question by:petewinter
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36484168
Can you post the error?
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36484187
Try using the full pathname and see if that fixes the problem:
 
<?php include("http://mysite.com/templates/header2.tpl"); ?>

Open in new window


If it still is not showing up, I would ensure that you are updating the proper header.php file in the proper theme.
0
 

Author Comment

by:petewinter
ID: 36484241
PragmatiCoder - No error. Just not displaying

OmniUnlimited - Tried the pathname and it did not fix the problem.

I can get around the issue including in the same folder or updating the header.php file, but wanted to work out why it didn't work?
0
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 36484320
If you are absolutely sure that you are updating the correct header.php file in the correct theme (ie you can make other changes to the file and they show up) then you have to have a problem with the path.

There is some handy code listed on http://php.net/manual/en/function.include.php by bimal at sanjaal dot com that says the following:

When two different files located in separate directories try to INCLUDE/REQUIRE the relative file names, this may help you correctly FIND the included files.

The code is a snapshot only. Your environment might change.

<?php
$now_at_dir = getcwd();
chdir(realpath(dirname(__FILE__).'/../../../somewhere/'));

# Out of the general area
require_once('a_differnet_path/browse_wine.php');

chdir($now_at_dir);
?>

The basic trick is in saving the current directory, changing to the required directory, including the file, and then return back to the original directory.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36484329
DId you check permissions on the header2.tpl file?

Also, include works at the file system file, not the web server level so /templates would be a top level folder in the file system. Maybe you should try making the path relative to the current folder by changing it from

<?php include("/templates/header2.tpl"); ?>

to

<?php include("./templates/header2.tpl"); ?>

Note the extra 'dot'

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36484332
Typo alert

file system file   = file system LEVEL

Sorry.

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36484532
Try
<?php
   $path = bloginfo("template_url")."/header2.tpl";
   include($path);
?>
0
 

Author Closing Comment

by:petewinter
ID: 36484630
Many thanks
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36484637
Try using this to include it:

Rename your file to header2.php

Then to include it in your template you would use:
<?php get_template_part('/top/header2'); ?>

Open in new window

0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36484652
No problem.  Best of luck to you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now