if is_frontpage to display some posts from category don't work
-
Hello everyone,
i have this code on my index.php:
<div id="recept"> <h2 class="recepty">Recepies</h2> <?php query_posts('category_name=recepty&showposts=1'); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h2> <a href="#"><img class="recepty-87x85" alt="image" src="<?php bloginfo('template_directory'); ?>/images/pancakes.png" /></a> <?php the_content ('more info'); ?> <?php endwhile; ?> <?php else : ?> <p>There are no recepies</p> <?php endif; ?> </div>
As it is it works perfect.
But i want that whole DIV to show only on front page. I know the sintaxe and i’m using it on any different blocks of code, but if i do this:
<?php if (is_front_page()); ?> <div id="recept"> <h2 class="recepty">Recepies</h2> <?php query_posts('category_name=recepty&showposts=1'); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <a href="#"><img class="recepty-87x85" alt="Pala?inky" src="<?php bloginfo('template_directory'); ?>/images/pancakes.png" /></a> <?php the_content ('more info'); ?> <?php endwhile; ?> <?php else : ?> <p>There are no recepies</p> <?php endif; ?> </div> <?php endif; ?>
It doesn’t work – on fronpage, there is nothing even on different pages. I think it have something to do with if statements, but i’m not goog at PHP. I’ve tried this also:
<?php if(is_front_page()) : ?> <div id="recept"> <h2 class="recepty">Recepies</h2> <?php query_posts('category_name=recepty&showposts=1'); ?> <?php while(have_posts()) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <a href="#"><img class="recepty-87x85" alt="Pala?inky" src="<?php bloginfo('template_directory'); ?>/images/pancakes.png" /></a> <?php the_content ('more info'); ?> <?php endwhile; ?> <?php else : ?> <p>There are no recepies</p> </div> <?php endif; ?>
But it only make it worst – it just display “There are no recepies” and crash fallowing DIVs.
Also tried this also:
<div id="recept"> <h2 class="recepty">Recepies</h2> <?php query_posts('category_name=recepty&showposts=1'); ?> <?php if(have_posts() && is_front_page() ) : while(have_posts()) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <a href="#"><img class="recepty-87x85" alt="Pala?inky" src="<?php bloginfo('template_directory'); ?>/images/pancakes.png" /></a> <?php the_content ('more information'); ?> <?php endwhile; ?> <?php else : ?> <p>There are no recepies</p> <?php endif; ?> </div>
Doesn’t work – still just writing “There are no recepies” even on front page (and yes, i have 1 post in recepty category, it works fine without ‘is_front_page’ statement).
If anybody can help, pleas do it ??
- The topic ‘if is_frontpage to display some posts from category don't work’ is closed to new replies.