0

I have to display the posts belonging to a particular category in the home page.As I am new to word press I don't know how to do it.PLease help me

-1

Use the following codes in the page.php file or in the home page template if you have created any. Use Child theme to edit your theme files

if( is_home() || is_front_page() ) {
    $args = array(
        'posts_per_page'   => -1, // To show all the posts
        'cat' => cat_id // Replace cat_id with the actual category id
    );

    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
}

For more detail, see the function Reference

| improve this answer | |
  • The home.php template file is reserved for the blog posts index, and should not be used as a custom site front page template. For that purpose, use front-page.php, or create a custom page template. – Chip Bennett Oct 4 '13 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.