Viewing 8 replies - 1 through 8 (of 8 total)
  • I put similar code in a Loop in a Page Template and it worked just fine.

    Thread Starter elistr

    (@elistr)

    Thank MichaelH for reply!

    Can you post here your part of code (where loop is)?

    This does not go 🙁

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php query_posts('category_name=Promo'); ?>
    
     <?php endwhile; else: ?>
     <p>Sorry, no posts matched your criteria.</p>
     <?php endif; ?>

    Thank you for reply!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    The query_posts() call should go BEFORE the if (have_posts()) piece. Like so:

    <?php query_posts('category_name=Promo'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    ...
    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    query_posts always needs to be before the Loop.

    Thread Starter elistr

    (@elistr)

    thank you for reply, but I am starting to be lame duck.
    I add this code to sidebar – where Promo is (http://czechbracelet.info)

    <?php query_posts('category_name=Promo'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    But the result of this code is Sorry, no posts matched your criteria. 🙁

    Try this:

    <?php
    $myposts = query_posts('category_name=Uncategorized');
    if ($myposts):
    foreach ($myposts as $post):
    setup_postdata($post);
    the_title();
    endforeach;
    else :
    // Nothing Found
    endif;
    ?>

    Thread Starter elistr

    (@elistr)

    Thank you for this code, but it shows anything different.

    I have changed “Uncategorized” to Promo (http://czechbracelet.info/?cat=48) it should show 2 links to 2 articles (Mike Jones v Praze už 20. ledna (Roxy),BBARÁK # 68 + Indy & Wich – Kids On The Click Tour 2007 DVD)

    But it shows this paragraph (without any links):

    Ke smrti legendárního Pimp C-ho se vyjádřili Bun-B a Mike JonesKe smrti legendárního Pimp C-ho se vyjádřili Bun-B a Mike Jones

    You can check this at http://czechbracelet.info/ (the second sidebar – left, centre).

    Any ideas?

    Yes, I just displayed the_title(); as an example. You will want to look at The Loop for possibilities to display such as <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    Thread Starter elistr

    (@elistr)

    Yesssssssss! Thank you so much! Viva la MichaelH and WordPress 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Query_posts does not go’ is closed to new replies.