bongkph
Member
Posted 3 months ago #
Hi, I am working on a theme that has no single.php but rather a loop.php. I wanted to add a floating ad so to do that I use the code
<?php include(TEMPLATEPATH . '/ads.php') ; ?>
But this code shows up even on homepage, so I wanted to show it only in "is_single." I am not a PHP guy so please help me with this.
Thanks a lot.
Use the is_single() conditional. Also, use get_template_part() instead of include(). e.g.:
if ( is_single() ) {
// include ads.php
get_template_part( 'ads' );
}
Note also: TEMPLATEPATH is deprecated. You should be using get_template_directory() in its place, if/when you need to return the template path.
<?php if( is_single() ) get_template_part( 'ads' );?>
bongkph
Member
Posted 3 months ago #
Thanks so much chip & esmi, it both worked.