Easy Worpress PHP Question

Garrett

music LOUD
Feb 4, 2008
3,847
131
0
I am playing around with Adsense on one of my blogs, but there are a few posts in particular that I'd like to remove it completely.

In my single.php file, I am doing this and it works fine

<?php if(!is_single('1')) : ?>
//adsense code
<?php endif; ?>

but when I try to exclude more posts, it's not working

<?php if(!is_single('1') || !is_single('2')) : ?>
//adsense code
<?php endif; ?>

and this doesn't work either

<?php if(!is_single('1') && !is_single('2')) : ?>
//adsense code
<?php endif; ?>

What am I doing wrong? newbish question I know but I'm learning :D
 


Try an array.

Edit:

is_single(array(17, 19, 1, 11)) Returns true when the single post being displayed is either post ID 17, post ID 19, post ID 1, or post ID 11.

Conditional Tags WordPress Codex

thanks!

after experimenting a bit, this code also works

Code:
<?php if(!is_single('1') && !is_single('2')) {?>
// adsense code
<?php }?>

In Wordpress what is the difference between

<?php if(!is_single('1')) : ?>
// adsense code
<?php endif; ?>

and this way with the curly braces?

<?php if(!is_single('1')) {?>
// adsense code
<?php }?>

Is one safer to use in most situations than the other?
 
Last edited:
I think the first one is 'wordpress syntax'.. i.e. for use within the loop.. the second one is just normal php. I would use the first... don't quote me on that though! Maybe somebody else can shed some light?
 
Basically you can use : and endif; instead of curly braces. It can make things a lot more readable.
 
Basically you can use : and endif; instead of curly braces. It can make things a lot more readable.

my code only seems to work WITH the curly braces. Like greyhat said, it probably is because its being used in the loop and (is_single) is a WP function
 
Last edited:
my code only seems to work WITH the curly braces. Like greyhat said, it probably is because its being used in the loop and (is_single) is a WP function


If the ' : ' and ' ; ' are part of PHP, they should work. Something must be worng. Post the code if you want....
 
"Mixing syntaxes in the same control block is not supported."
This is the short version from the link above ;)