Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Replace TEMPLATEPATH WordPress

  • SOLVED

Please can someone update this code for me as TEMPLATEPATH is deprecated.

<?php
$post = $wp_query->post;
if ( in_category('advice-and-ideas') ) {include(TEMPLATEPATH . '/single-advice-and-ideas.php');}
elseif ( in_category('travel') ) {include(TEMPLATEPATH . '/single-travel.php');}
else {include(TEMPLATEPATH . '/single-default.php');
}
?>

Answers (5)

2014-02-14

John Cotton answers:

<?php

$post = $wp_query->post;

if ( in_category('advice-and-ideas') ) {include( get_template_directory(). '/single-advice-and-ideas.php');}

elseif ( in_category('travel') ) {include(get_template_directory(). '/single-travel.php');}

else {include(get_template_directory(). '/single-default.php');

}
?>
Hey Jules!


julesphoto comments:

Bingo! Thanks John.

2014-02-14

Hariprasad Vijayan answers:

Hello,


<?php

$post = $wp_query->post;

if ( in_category('advice-and-ideas') ) {include(get_template_directory(). '/single-advice-and-ideas.php');}

elseif ( in_category('travel') ) {include(get_template_directory(). '/single-travel.php');}

else {include(get_template_directory(). '/single-default.php');

}

?>

2014-02-14

Arnav Joy answers:

try this

<?php

$post = $wp_query->post;

if ( in_category('advice-and-ideas') ) {include(get_stylesheet_directory_uri(). '/single-advice-and-ideas.php');}

elseif ( in_category('travel') ) {include(get_stylesheet_directory_uri(). '/single-travel.php');}

else {include(get_stylesheet_directory_uri(). '/single-default.php');

}

?>

2014-02-14

Navjot Singh answers:

<?php
$post = $wp_query->post;
if ( in_category('advice-and-ideas') ) {include(get_template_directory() . '/single-advice-and-ideas.php');}
elseif ( in_category('travel') ) {include(get_template_directory() . '/single-travel.php');}
else {include(get_template_directory() . '/single-default.php');
}

?>

Use this

2014-02-14

Remy answers:

Using get_template_part is better than include


<?php

$post = $wp_query->post;

if ( in_category('advice-and-ideas') ) {get_template_part( 'single-advice-and-ideas.php');}

elseif ( in_category('travel') ) {get_template_part('single-travel.php');}

else {get_template_part('single-default.php');

}

?>