function add_excluded_post_ids( $exclude_post_ids, $posts ) {
foreach( $posts as $post ) {
array_push( $exclude_post_ids, $post->ID );
}
return $exclude_post_ids;
}
$exclude_post_ids = array();
$latest_posts = get_posts( array(
'numberposts' => 3
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $latest_posts );
$health_posts = get_posts( array(
'numberposts' => 3,
'category' => get_category_by_slug( 'health' )->term_id, // Change accordingly
'exclude' => $exclude_post_ids
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $latest_posts );
$fitness_posts = get_posts( array(
'numberposts' => 3,
'category' => get_category_by_slug( 'fitness' )->term_id, // Change accordingly
'exclude' => $exclude_post_ids
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $fitness_posts );
$beauty_posts = get_posts( array(
'numberposts' => 3,
'category' => get_category_by_slug( 'beauty' )->term_id, // Change accordingly
'exclude' => $exclude_post_ids
) );
Now you have $latest_posts, $health_posts, $fitness_posts and $beauty_posts. Each one of them stores a set of 3 posts which you can use to generate your HTML. You can use a shortcode that outputs the whole HTML, then insert this shortcode within a "Page" and finally set your homepage to that "Static page".
Note $health_posts, $fitness_posts and $beauty_posts will store the latest posts that belong to those categories, respectively. If you wish to retrieve those posts by another parameter, like amount of views, or randomly, you'll have to use WP_Query
instead of get_posts()
.