How to select a certain post in Wordpress?

0

I would like to select posts to add a class just for it.

For example I have lines with 3 posts each, and I would like to select 3 posts to add a division to the next line.

Or would you have another way to do this?

    
asked by anonymous 21.05.2014 / 14:42

2 answers

1

The best way to do this, in my opinion, is to use CSS3 selectors for example:

p:nth-child(n+3) { color:#f00; }

So you always select the third p of a given element.

    
21.05.2014 / 20:20
0

You can do this by counting posts within the loop and creating 3 posts:

<?php 
$i = 0;
if ( have_posts() ) {?>
   <div class="row"><?php //abre a primeira linha
        while ( have_posts() ) {
        $i++;
        if (($i > 3) & (($i % 3) === 1)){ //se for o primeiro de uma nova linha
        ?></div><div class="row"><?php //fecha a linha anterior e abre uma nova      
        }

        the_post(); 

        //
        // Conteúdo do post
        //

    }?></div><?php // end while fecha a última linha
} // end if
?>

And in css:

.row {border-bottom: 5px solid red;}

This code is just a sketch to give you an idea ... it should be improved according to your template.

    
10.02.2015 / 21:55