Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress PHP for WordPress PHP Basics for WordPress The Loop

geoffrey
geoffrey
28,736 Points

This conditional statement doesn't look logic to me.

While watching the video, at 1:53, Zac tells that the conditional if statement, simply checks if this page is the home page AND the front page, if so, the following code is executed, if not, the code inside the else statement is executed.

That's not difficult to understand but to me, the if conditional statement checks if we are indeed on the home page and NOT the front page, as we have an exclamation mark just in front the is_front_page() function...

What am I' missing here please ? Can someone enlight me...

Here is the code that I'm pointing out:

<?php if ( is_home() &&  ! is_front_page() ) : ?>
         //execute some code

I guess is_home returns true as we are on the home page, the is_front_page() function is according to the codex, a boolean function as well, returning TRUE when the main blog page is displayed. To me, It sounds like that's the case here. So the code shouldn't be displayed as TRUE && FALSE => is FALSE.

I guess my lack of understanding comes from the fact the home page isn't a blog page, so is_front_page() returns false, but with the preceeding exclamation mark, It becomes true and then the code inside the if statement gets executed...

7 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

What I think is confusing everyone (including me) is Zac says, "OR" when the operator is clearly an "AND".

The line of code is checking to see if it is on the Home page AND IS NOT the Front Page, which makes no sense.

Could Zac Gordon please help to clarify this?

Thanks. :)

geoffrey
geoffrey
28,736 Points

I still don't get it, I'm sorry...

<?php if ( is_home() &&  ! is_front_page() ) : ?>
         //execute some code

Why does Zac say in the video about this line above:

if It's the home OR frontpage then output this...

To me this piece of code means: If you are on the home page AND NOT on the front_page then...

I'm confused.

Andi Wilkinson
Andi Wilkinson
26,822 Points

the naming conventions of WordPress mean that front_page.php will be the home page of your website if that exists.

if you choose to have your blog as the home page, you could use home.php, or even default back up the template hierarchy to index.php - in which case the home page would not be front page.

Chriss Benitez
Chriss Benitez
2,222 Points

omg you are right it is an AND and there is no logic now xD. But that isn't a simple AND, theres a exclamation character "&& !" So it makes sense :)

Paulius Vitkus
Paulius Vitkus
24,230 Points

It's simple doublecheck about if some piece of code is at the homepage of site.

Jake Ford
Jake Ford
9,230 Points

geoffrey I was wondering the same thing. The code makes no sense. If it is_home, but not the front_page is what I am reading..