Yes you can do this. Here’s your PHP code wrapped inside an HTML structure with proper formatting and comments, ready to be used in a WordPress template file (like front-page.php or home.php). This example includes the logic to:
Show 1 most recent post from specific categories first
Then show 10 most recent posts from all categories
Then show 10 most recent posts per category
<?php
// 1. Show 1 most recent post from specific categories
$specific_cat_ids = array(3, 5, 7); // Replace with your category IDs
$args = array(
'posts_per_page' => 1,
'category__in' => $specific_cat_ids,
'orderby' => 'date',
'order' => 'DESC',
);
$featuredQuery = new WP_Query($args);
if ($featuredQuery->have_posts()) {
echo '<section class="featured-post">';
echo '<h1>Featured Post</h1>';
while ($featuredQuery->have_posts()) {
$featuredQuery->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="humbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail();
} ?>
</div>
<div class="content">
<?php the_content('Read More »'); ?>
</div>
<?php }
echo '</section>';
wp_reset_postdata();
}
// 2. Show 10 most recent posts from all categories
$args = array(
'posts_per_page' => 10,
);
$customQuery = new WP_Query($args);
if ($customQuery->have_posts()) {
echo '<section class="all-cats">';
echo '<h1>Latest Posts</h1>';
while ($customQuery->have_posts()) : $customQuery->the_post(); ?>
<article>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="humbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail();
} ?>
</div>
<div class="content">
<?php the_content('Read More »'); ?>
</div>
</article>
<?php
endwhile;
echo '</section>';
wp_reset_postdata();
}
// 3. Show 10 most recent posts per category
$allcats = get_categories('child_of=".get_query_var("cat'));
foreach ($allcats as $cat) :
$args = array(
'posts_per_page' => 10,
'category__in' => array($cat->term_id)
);
$customInCatQuery = new WP_Query($args);
if ($customInCatQuery->have_posts()) :
echo '<section class="category-posts">';
echo '<div id="posts-header-container"><h1><span>Recently from '.$cat->name.'</span></h1></div>';
while ($customInCatQuery->have_posts()) : $customInCatQuery->the_post(); ?>
<article>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="humbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail();
} ?>
</div>
<div class="content">
<?php the_content('Read More »'); ?>
</div>
</article>
<?php
endwhile;
echo '</section>';
else :
echo '<p>No post published in: '.$cat->name.'</p>';
endif;
wp_reset_postdata();
endforeach;
?>
How to Use:
Replace the category IDs in $specific_cat_ids = array(3, 5, 7); with your desired category IDs.
Save this as your homepage template or insert the PHP part into your existing homepage template.