How to select a particular post in Wordpress?

Asked

Viewed 275 times

0

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

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

inserir a descrição da imagem aqui

Or there’d be another way to do it?

2 answers

1

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

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

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

  • This way it works. I would like to know if you have a way to select by Wordpress query itself. Because that way if I’m not mistaken doesn’t work in some versions of IE.

0

You get this by counting the posts inside the loop and creating lines from 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 an outline to give an idea... should be improved according to your template.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.