It becomes slightly more complicated. We need two WP_Query objects, some calculations and a for-loop.
For PHP to know about the right format, we can use a simple format array. In following example, I will be using categories to determine the two WP_Query builds.
First, we build the base variables:
<?php
// Build format
// 0 means not featured - 1 means featured.
$format = array(1, 0, 1, 1, 0, 0);
// Retrieve normal posts EXCLUDING category with ID 11 (Featured)
$normal_posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 999,
'cat' => '-11'
));
// Retrieve featured posts ONLY INCLUDING category with ID 11 (Featured)
$featured_posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 999,
'cat' => 11
));
// Calculate total amount of posts
// from our two WP_Query results
$posts_total = $normal_posts->post_count + $featured_posts;
// Setup current post index
$post_index = 0;
Next, we start 'the loop' or iteration:
// Iterate every post from two queries
for($i = 0; $i < $posts_total; $i++){
In which we calculate current format index:
// Calculate which type of post to display based on post index
// We use modulo to get the right $format index
$post_format_index = $post_index % count($format);
$current_format = $format[$post_format_index];
Finally, display the right type of post:
// Display to frontend based on format
switch ($current_format) {
case 1:
// Featured
$featured_posts->the_post();
the_title();
// Your content
print '<br>';
break;
default:
// Not Featured
$normal_posts->the_post();
the_title();
// Your content
print '<br>';
break;
}
$post_index++;
}
?>
That's it. You could take this a step further by adding another WP_Query and format.
$format = array(1, 0, 1, 1, 2, 2);