You can do this with different techniques-
-
One of them is with
get_posts()
function. You can pass parameter inside it and get an array of specific posts. Then you’ve to run aforeach
loop to show those posts as you want. -
And you can also use
WP_Query()
. It also takes parameter likeget_posts()
but after every query you need to reset the query withwp_reset_query()
.
For first case-
//getting header with get_header() - not important
...some code...
//and here I want to add some specific post from specific category(ONLY this specific post)
$args_1 = [
'category__in' => 1 // category id
];
$posts_1 = get_posts( $args_1 );
foreach ($posts_1 as $post_1){
// show posts as you want
}
//another specific post from specific category(only this specific post again).
$args_2 = [
'category__in' => 2 // category id
];
$posts_2 = get_posts( $args_2 );
foreach ($posts_2 as $post_2){
// show posts as you want
}
//and so on
//getting footer with get_footer() - not important
For second case-
//getting header with get_header() - not important
...some code...
//and here I want to add some specific post from specific category(ONLY this specific post)
$args_1 = [
'category__in' => 1 // category id
];
$posts_1 = new WP_Query( $args_1 );
while ( $posts_1->have_posts() ) : $posts_1->the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
endwhile; // End of the loop.
wp_reset_query();
//another specific post from specific category(only this specific post again).
$args_2 = [
'category__in' => 2 // category id
];
$posts_2 = new WP_Query( $args_2 );
while ( $posts_2->have_posts() ) : $posts_2->the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
endwhile; // End of the loop.
wp_reset_query();
//and so on
//getting footer with get_footer() - not important