• Resolved jabbo126

    (@jabbo126)


    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 ??

Viewing 1 replies (of 1 total)
  • Thread Starter jabbo126

    (@jabbo126)

    Ok, i have solution – in case it help somebody else. You need to reset query before if statement. So it may look like this:

    <div id="recept">
                <h2 class="recepty">Recepies</h2>
                <?php wp_reset_query(); ?>
                <?php if ( have_posts() && is_front_page() ) : ?>
    			<?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 : ?>
                	<?php get_sidebar(); ?>
                <?php endif; ?>
            </div>
Viewing 1 replies (of 1 total)
  • The topic ‘if is_frontpage to display some posts from category don't work’ is closed to new replies.