How to make posts with different markup and different classes?

<div> <div class='row-1 left'> <div class='left'> post 1 </div> <div class='center'> post 2 </div> <div class='right'> post 3 </div> </div> <div class='row-2 center'> <div class='left_1'> post 4 </div> <div class='center_1'> post 5 </div> <div class='right_1'> post 6 </div> </div> <div class='row-3 right'> <div class='left'> post 7 </div> <div class='center'> post 8 </div> <div class='right'> post 9 </div> </div> </div> 

    1 answer 1

    It is necessary to get all the posts in the array, and then manipulate this array.

     $args = array( 'numberposts' => -1, 'post_type' => 'post', ); $posts = get_posts( $args ); for ($i=0; $i < count($posts); $i+=9) { ?> <div> <div class='row-1 left'> <div class='left'><?php if ($i < count($posts)) { echo $posts[$i]->post_content; } ?></div> <div class='center'><?php if (($i + 1) < count($posts)) { echo $posts[$i + 1]->post_content; } ?></div> <div class='right'><?php if (($i + 2) < count($posts)) { echo $posts[$i + 2]->post_content; } ?></div> </div> <div class='row-2 center'> <div class='left_1'><?php if (($i + 3) < count($posts)) { echo $posts[$i + 3]->post_content; } ?></div> <div class='center_1'><?php if (($i + 4) < count($posts)) { echo $posts[$i + 4]->post_content; } ?></div> <div class='right_1'><?php if (($i + 5) < count($posts)) { echo $posts[$i + 5]->post_content; } ?></div> </div> <div class='row-3 right'> <div class='left'><?php if (($i + 6) < count($posts)) { echo $posts[$i + 6]->post_content; } ?></div> <div class='center'><?php if (($i + 7) < count($posts)) { echo $posts[$i + 7]->post_content; } ?></div> <div class='right'><?php if (($i + 8) < count($posts)) { echo $posts[$i + 8]->post_content; } ?></div> </div> </div> <?php } wp_reset_postdata(); 
    • Thanks understood, but already did something like this s019.radikal.ru/i642/1704/e7/ea8e3739f30c.png navatsof.vh91.hosterby.com/blog - Anton Essential
    • That's interesting, is it possible to somehow push through another category into arguments already in a cycle, for example, display posts from one category and then go if and change the parameter of the category array, let's say for category 2, hang out post and then again by changing the parameters of the category array to those were, in other words, to change $ args already in the loop and then return to the previous iteration to the previous value - Anton Essential
    • No, of course. The request to the database is executed once, and in the WP cycle it issues posts from the memory. - KAGG Design