Syntax error.
This:
<?php include("<?php echo get_stylesheet_directory_uri() ?>/featured-content/fp-<?php the_ID(); ?>.htm ");?>
…should be this:
<?php include( get_stylesheet_directory_uri() . '/featured-content/fp-' . get_the_ID() . '.htm' ); ?>
Thanks, Chip. I knew I should figure out how to get rid of that nested php. However, the include still does not work. Shouldn’t it at least work when I hard code the full URL to a specific file, as in Line 3?
There are no error messages, or any trace of the request in the output. It’s like the line just gets skipped in processing.
BTW, there is a php include line that’s built into the theme at the bottom of this same page that runs fine. So it seems like there is something within this div that is being handled differently, somehow.
I’m mystified.
1) Does “http://mydomain.com/wp-content/themes/Essence-RFF/featured-content/fp-56.htm” exist?
2) Are you calling the include() inside the Loop?
3) Why are you including a .htm file, instead of a .php file?
1) Yes, the file exists, and the URL works. Sorry, it’s in a protected directory so I can’t share it at the moment.
2) Yes; this is a Page Template in the Child Theme folder. As I mentioned <?php include(TEMPLATEPATH."/sidebar_right_page.php");?> is on the same page, and works correctly.
3) The file only contains a single paragraph of text, so I didn’t think it needed to be .php. (I have actually tried renaming it, though, to see if that would make a difference, but no cigar.)
Woah! That’s it! The security on the directory is preventing access by the system! I’ll see if I can figure out how to give the server access.
Thanks for all your help. There’s one more lesson learned!
2) Yes; this is a Page Template in the Child Theme folder. As I mentioned <?php include(TEMPLATEPATH.”/sidebar_right_page.php”);?> is on the same page, and works correctly.
That’s not actually what I was asking. π Just because the code is called from inside a custom page template (or any other template file or template-part file) doesn’t mean that it is executed inside the Loop. The Loop is the part that outputs the post data, e.g.
if ( have_posts() ) : while ( have_posts() ) : the_post();
// IS THE CODE CALLED HERE?
endwhile; endif;
But, to cut to the chase, try this, and tell me what gets output:
$featured_content_filepath = get_stylesheet_directory_uri() . '/featured-content/fp-' . get_the_ID() . '.htm';
var_dump( $featured_content_filepath );
Oh, and one other thing:, you need to use get_stylesheet_directory(), rather than get_stylesheet_directory_uri(). So, try this:
<?php include( get_stylesheet_directory() . '/featured-content/fp-' . get_the_ID() . '.htm' ); ?>
And if it still doesn’t work, tell me what is output from this:
$featured_content_filepath = get_stylesheet_directory() . '/featured-content/fp-' . get_the_ID() . '.htm';
var_dump( $featured_content_filepath );
Woah! That’s it! The security on the directory is preventing access by the system! I’ll see if I can figure out how to give the server access.
Thanks for all your help. There’s one more lesson learned!
This is probably because you’re using get_stylesheet_directory_uri() (which returns a URL), rather than get_stylesheet_directory() (which returns a filepath).
The PHP include() function expects a filepath, and most servers have PHP configured NOT to allow use of URLs in include(), for security reasons.
Ok, that makes loads of sense all the way around.