5

i tried many conditions to my footer.php section to include this function in my front page only and not on blog page...but it just pops up on both pages or none of them...can anyone explain the fault ?

 <?php if( is_home() && is_front_page()   ) : ?>
  <div id="blurbs">
    <ul>
  <?php $the_query = new WP_Query( 'showposts=3' ); ?>

   <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
   <div class="postwrapper">
   <?php the_post_thumbnail(); ?>   <li style="display:inline; font-size: 20px; font-weight:light;"><?php the_title(); ?></li>
<br class="clear">
  <li style=" font-size: 14px; font-weight:light;"><?php the_content(); ?></li>
 </div>
 <?php endwhile;?>
 </ul>
 </div>
 <?php endif; ?>
1
  • What's the output from var_dump( is_home() ); and var_dump( is_front_page() ); on both these pages?
    – birgire
    Commented May 30, 2015 at 10:55

4 Answers 4

17
 <?php if( is_front_page() ) : ?>

is_home relates to the posts page according to your reading settings. is_front_page always returns true on the front page.

4
  • yeah but what should i do to saatisfy the condition in my question above...how to include it in only one page and not both pages.....?? Commented May 30, 2015 at 11:06
  • Try the updated code and mark as accepted and give me up vote if works. Commented May 30, 2015 at 11:21
  • i already tried it without wp_reset_query(); but it didnt work.. Commented May 30, 2015 at 11:25
  • My solution relates purely to the use of conditional tags and works perfectly for me so the problem is at your end. Commented May 31, 2015 at 5:02
0
  • On the site front page, is_front_page() will always return TRUE, regardless of whether the site front page displays the blog posts index or a static page.
  • On the blog posts index, is_home() will always return TRUE, regardless of whether the blog posts index is displayed on the site front page or a separate page.

So try following condition instead:

<?php if( 'page' == get_option( 'show_on_front' ) && is_front_page()   ) : ?>
5
  • not working...still both pages show the content Commented May 30, 2015 at 10:23
  • <?php wp_reset_query(); ?>...this really solved my problem...wondering what more wonders can WP do :) Commented May 30, 2015 at 11:15
  • one more thing ..its written that do not use this until absolutely neccessary..will it casue any future errors or something else Commented May 30, 2015 at 11:18
  • 3
    @PiyushRawat wp_reset_query() is wrong. It is used with query_posts which you should never ever used. The correct way to reset WP_Query is wp_reset_postdata(). One note on query_posts, it breaks the main query and can cause the issue that you are having :-) Commented May 30, 2015 at 11:31
  • @PieterGoosen will check with it too...atleast its functioning...btw thanks for the info Commented May 30, 2015 at 11:34
-1

wp_reset_query(); solved the problem...it was maybe due to loops running prior to this one..

1
  • 2
    As I said in another comment, your issue is probably related to the use of query_posts. Note, you should reset WP_Query with wp_reset_postdata() Commented May 30, 2015 at 11:34
-1

wp_reset_query(); is realy worked, if you use custom queries before call check front page

1
  • 1
    Hello and thank you for your answer! Could you edit your answer using the edit button above and explain where the question asker would put or use wp_reset_query() and why it may help them in this scenario?
    – Howdy_McGee
    Commented Jun 22, 2018 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.