Forums

[closed] Alternate query_posts output (3 posts)

  1. albertpr9
    Member
    Posted 2 years ago #

    Hi,

    How can I get the query_posts to alternate the output?

    Ex; instead of this:

    <h1>Header 1</h2>
    <p>text</p>
    <!-- end of post -->
    <h1>Header 2</h2>
    <p>text</p>
    <!-- end of post -->
    <h1>Header 2</h2>
    <p>text</p>
    <!-- end of post -->

    I'd like to get this:

    <h1>Header 1</h2>
    <p>text</p>
    <!-- end of post -->
    <h1 class="hd2">Header 2</h2>
    <p>text</p>
    <!-- end of post -->
    <h1>Header 2</h2>
    <p>text</p>
    <!-- end of post -->

    You know what I mean??? So I can get the posts presented in an alternate way from each other...

    Thanks for the help in advance.

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    one of the ways is to use a counter, check for odd/even, add the extra class to odd headers, increment the counter after the post.

    <?php $counter=0;
    if (have_posts()) :
       while (have_posts()) :
    ?>
    <h1 <?php if($counter%2 != 0) { echo 'class="hd2"'; } ?>><?php the_title(); ?></h1>
     <?php     the_content();
    $counter++;
       endwhile;
    endif;
    ?>

    for a different way see: http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/posts-that-have-alternating-colors/

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    Continue discussion here:
    http://wordpress.org/support/topic/362571

    I also deleted another thread of the same subject.

    @albertpr9 - Please do not post duplicate topics.

Topic Closed

This topic has been closed to new replies.

About this Topic