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.
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/
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.