Search code examples
phpwordpressinclude-path

php include (cannot get correct path)


I have a file that resides in:

/Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/sidebar-left-big.php

I have another file in sub directory:

/Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/template_directorypress/_gallerypage.php

And in _gallerypage.php I have php include:

<?php include('../sidebar-left-big.php'); //left sidebar, category navigation and ads ?>

Error I get:

Warning: include(../sidebar-left-big.php) [function.include]: failed to open stream: No such file or directory in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/template_directorypress/_gallerypage.php on line 9

Warning: include() [function.include]: Failed opening '../sidebar-left-big.php' for inclusion (include_path='.:') in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/template_directorypress/_gallerypage.php on line 9

It seems to me I'm doing everything correctly.

I thought that maybe problem is that _gallerypage.php is loaded via include in another file, so ../ relative to that leads to error. But error doesn't say anything as to where it thinks path to sidebar-left-big.php is.


Solution

  • use include dirname(__FILE__).'/../sidebar-left-big.php';