• srpd

    (@srpd)


    Hi, i have a question.
    I’m using this script

    <div>
    <?php
    $sticky=get_option('sticky_posts');
    $args=array( 'cat'=>20, 'caller_get_posts'=>1, 'post__not_in' => $sticky, 'posts_per_page' => 4 );
    query_posts($args);
    ?>
    <?php $c = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php include (TEMPLATEPATH . '/index.php'); ?>
    <?php endwhile; ?>
    <?php unset ($c); ?>
    <?php  wp_reset_query(); ?>
    </div>
    
    <div>
    <?php
    $sticky=get_option('sticky_posts');
    $args=array( 'cat'=>3, 'caller_get_posts'=>1, 'post__not_in' => $sticky, 'posts_per_page' => 4 );
    query_posts($args);
    ?>
    <?php $c = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php include (TEMPLATEPATH . '/index2.php'); ?>
    <?php endwhile; ?>
    <?php unset ($c); ?>
    <?php  wp_reset_query(); ?>
    </div>

    two different loops to choose category 3 and category 20 posts excluding sticky post. I’m trying to change this by using one loop, something like

    <div>
    <?php
    $sticky=get_option('sticky_posts');
    $test=array('3','20');
    $args=array( 'cat'=>$test, 'caller_get_posts'=>1, 'post__not_in' => $sticky, 'posts_per_page' => 4 );
    query_posts($args);
    ?>
    <?php $c = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category('3') )  { include 'index.php'; } ?>
    <?php elseif ( in_category('20') )  { include 'index2.php'; } ?>
    <?php } else { } ?>
    <?php endwhile; ?>
    <?php unset ($c); ?>
    <?php  wp_reset_query(); ?>
    </div>

    but obiovusly it doesn’t work. Is possible to do what i need? i’m not a coder i’m trying and trying but….
    thanks in advance.

  • The topic ‘how to use multiple loops’ is closed to new replies.