4

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; ?>
  • What's the output from var_dump( is_home() ); and var_dump( is_front_page() ); on both these pages? – birgire May 30 '15 at 10:55
10
 <?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.

  • 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.....?? – Piyush Rawat May 30 '15 at 11:06
  • Try the updated code and mark as accepted and give me up vote if works. – Brad Dalton May 30 '15 at 11:21
  • i already tried it without wp_reset_query(); but it didnt work.. – Piyush Rawat May 30 '15 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. – Brad Dalton May 31 '15 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()   ) : ?>
  • not working...still both pages show the content – Piyush Rawat May 30 '15 at 10:23
  • <?php wp_reset_query(); ?>...this really solved my problem...wondering what more wonders can WP do :) – Piyush Rawat May 30 '15 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 – Piyush Rawat May 30 '15 at 11:18
  • 2
    @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 :-) – Pieter Goosen May 30 '15 at 11:31
  • @PieterGoosen will check with it too...atleast its functioning...btw thanks for the info – Piyush Rawat May 30 '15 at 11:34
-1

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

  • 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() – Pieter Goosen May 30 '15 at 11:34
-1

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

  • 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 Jun 22 '18 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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