Answer the question
In order to leave comments, you need to log in
How to correctly display posts with different layouts?
Hello, while studying wordpress, I encountered such a problem that there are places on the site where posts are displayed with different layouts, here is an example.
These two blocks are displayed with different layout. And there is a third block, which is located almost at the footer, and looks like this
. How can I display posts in such different layouts?
Answer the question
In order to leave comments, you need to log in
For example, you can check the sequence number of the cycle and include the required template
if ( $query->have_posts() ) {
$i = 1;
while ( $query->have_posts() ) {
$query->the_post();
if ( $i == 1 ) {
get_template_part( 'templates/template-one' ); // первый
} elseif( $i == 2 ) {
get_template_part( 'templates/template-two' ); // второй
} else {
get_template_part( 'templates/template-common' ); // остальные
}
$i++;
}
} else {
// Постов не найдено
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question