is_home, and is_front_page conditional problem

I have this snippet in a “portfolio-loop.php” file. I’m using get_template_part to display the loop on the front page and on other pages.

I have this within the loop:

<?php if( !is_home() || !is_front_page() ) { ?>
  <p><?php the_time('F Y'); ?></p>
<?php endif } ?>

I can’t seem to get it to exclude the front page. Could it because it’s in it’s own template?

edit

Ok I fixed some of my semantic errors thanks to s_ha_dum and Tom Nowell. I’ve tried the following variations:

<?php if ( !is_home() && !is_front_page() ) { ?> 
    <!--nada -->
<?php } else { ?>
    <p><?php the_time('F j, Y'); ?></p>
<?php } ?>



//dropping is_home() and trying to keep it as simple as possible
<?php if(!is_front_page()) { ?>
    <p><?php the_time('F j, Y'); ?></p>
<?php } ?>

I still can’t hide the time on the front page. At best ‘<–nada–>’ will appear on both my home page (home.php) and on my archive (category-blog.php). Is my custom category page seen as a front page as well?

edit 2

What I’m trying to do in plain english:

I have a loop on my front page (static, home.php) displaying three of my latest blog posts via get_template_part. The same loop is used for my category-blog.php/archive listing but shows the last 10 posts. I do not want to show the date/time on the front page to keep the layout cleaner, only on the other pages that this loop is displayed on.

5 Answers
5

Let’s see if I can confuse myself.

If either of your two OR conditions is true the code executes.

is_home and is_front_page can return true for different pages, negated in your case. If you have a static from page, which it sounds like you do, then is_home is the blog index page.

Note: WordPress 2.1 handles this function differently than prior
versions – See static Front Page. If you select a static Page as your
frontpage (see is_front_page()), this tag will be applied to your
“posts page”.

http://codex.wordpress.org/Function_Reference/is_home

What that means is that is_home will be false for every page except your blog index, which means that your !is_home conditional is true for every page except that blog index page and your code will run almost all the time.

Now the docs for is_front_page.

It returns TRUE when the main blog page is being displayed and the
Settings->Reading->Front page displays is set to “Your latest posts”,
or when is set to “A static page” and the “Front Page” value is the
current Page being displayed.

http://codex.wordpress.org/Function_Reference/is_front_page

There are two possibilities depending on your settings. It might return true for your blog index page, or it might return true for your static page. I think that you have a static front page so is_front_page will return true for that page and the !is_front_page conditional will be false. Because !is_home is (probably, if I am following you) true the code still executes.

If you want to exclude <p><?php the_time('F Y'); ?></p> from both the blog index and the static front page, then negate the entire OR statement:

if( !(is_home() || is_front_page()) )

If either is true then the whole thing is false.

If you want to exclude it only from the front page, then you shouldn’t need the !is_home part at all.

If you use && instead of || then both is_home and is_front_page would have to be false for the code to run. That is, you are not on the blog index and not on the front at the same time.

Leave a Comment