Solved

include file not working

Posted on 2011-09-05
10
426 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
Comment Utility
Can you post the error?
0
 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
Typo alert

file system file   = file system LEVEL

Sorry.

0
 
LVL 27

Expert Comment

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

Author Closing Comment

by:petewinter
Comment Utility
Many thanks
0
 
LVL 23

Expert Comment

by:jeremyjared74
Comment Utility
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
Comment Utility
No problem.  Best of luck to you!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 27
how to resize preview image 4 28
How can I expand text with explaination 5 18
php image upload 3 24
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

8 Experts available now in Live!

Get 1:1 Help Now