Question

I have a slideshow on a php page that uses $folder = opendir($dirpath); to access images in a folder. When I enter the url of said php file all works well, however once I call this php from inside a wordpress page it no longer accesses the image folder.

I'm guessing this is due to the fact the path changes to where the php is being called to. I just can't seem to work out what I need to replace '$dirpath' with so I can access the folder url.

The tag <?php bloginfo('stylesheet_directory'); ?>/imagefolder accesses the folder when not inside a php tag, however I don't know know I can add this inside php tags.

I've tried:

$dirpath = bloginfo('stylesheet_directory')."/imagefolder";
$dirURL = "";
$folder = opendir($dirpath);

but it's not correct.

Any help would be appreciated.

Was it helpful?

Solution

From the documentation on bloginfo:

This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().

And checking the docs on get_bloginfo(), you'll see that's better to use get_stylesheet_directory_uri(), so your code would be

$dirpath = get_stylesheet_directory_uri()."/imagefolder";
$folder = opendir($dirpath);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top