I am trying to resolve a issue, sort of an issue, that I discovered while correcting other issues..
In short I have the following code: Single.php
<?php
$post = $wp_query->post;
if ( in_category( array('things-to-do'')) ) {include_once( $theme_path . 'single-to-do.php' );}
elseif ( in_category( array('hotels')) ) {include_once( $theme_path . 'single-hotel.php' );}
elseif ( in_category( array('event')) ) {include_once( $theme_path . 'single-event.php' );}
else {include_once( $theme_path . 'single-all.php' );}
?>
The error is:
Notice: Undefined variable: theme_path in single.php
I assume I need a function defining what $theme_path "means". I'm just not sure 100% the best route to get there.
Rempty answers:
Hello
if the single.php and the single-tp-do, single-hotel... and other files are in the same folder you don't need to use a $theme_path variable.
Luthfi Bintoro answers:
You can try to use get_template_part function for that :
<?php
$post = $wp_query->post;
if ( in_category( array('things-to-do'')) ) {
get_template_part( 'single','to-do');
}elseif ( in_category( array('hotels')) ) {
get_template_part( 'single','hotel');}
elseif ( in_category( array('event')) ) {
get_template_part( 'single','event');}
else {
get_template_part( 'single','all');
}
?>
Cesar Contreras answers:
you can use this code for resolved you problem, on the top of your file:
<?php $theme_path = get_bloginfo("stylesheet_directory"); ?>