I want to style every first post that comes on my main page.
What is the <?php
code for that
?
I want to style every first post that comes on my main page.
What is the <?php
code for that
?
Find
<?php while(have_posts()) : the_post(); ?>
Replace with...
<?php $countposts = 0; while(have_posts()) : the_post(); $countposts++; ?>
Then wherever you want to do something different...
<?php if($countposts == 1) {
// YOUR CODE
} ?>
So for example, lets say you have the following piece of HTML...
<div class="example">
And you wanted to add a class when it's the first post, it would then become.
<div class="example<?php if($countposts == 1) { ?> secondclass<?php } ?>">
Your HTML then becomes..
<div class="example secondclass">
All you need then do is add a CSS definition for that second class in your stylesheet.
Example:
.secondclass {
background-color: #000;
}This topic has been closed to new replies.