I want to show last 5 modified posts from a specific category called "Featured" on the front page just below the regular posts, but not on the subsequent subpages. I am using this code to show these last five posts. Everything seems to be working fine except these 5 posts also run on the subpages.
function modified_postsbycategory() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'featured', 'orderby' => 'modified', 'posts_per_page' => 5 ) );
// The Loop
if ( $the_query->have_posts() ) : ?>
<?php
while ( $the_query->have_posts() ) :
$the_query->the_post();
get_template_part( 'template-parts/content', 'modified' );
// End the loop.
endwhile;
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
<?php wp_reset_postdata(); ?>
<?php
}
// Add a shortcode
add_shortcode('categoryposts', 'modified_postsbycategory');
I am using this conditional tag just after the function starts, but I think I am not doing the right way.
<?php if (is_front_page() && !is_paged() ){ ?>
Could you please help me?
PS: Please check the code too and correct me if any errors found. I am just a learner, not expert.
In Wordpress Front page can be either
IF it is Your latest posts then condition will be
<?php if (is_home()){ ..... } ?>
Otherwise
<?php if (is_front_page()){ ..... } ?>
you just need to check if it's a front page
<?php if (is_front_page()){ ?>