Support » Theme: Sensible WP » Home section blog

  • Resolved benjee1984

    (@benjee1984)


    Hello, can you tell me how to define a specific category for displaying articles in the blog section of the home page ? Currently section displays all items. Thank you a lot.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Benjee,

    If you’d like to display only posts from a given category, you could try using this loop in the home page template:

    <?php $my_query = new WP_Query('cat=1'); // display only category 1 posts
    while($my_query->have_posts()) : $my_query->the_post(); ?>
    
      <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <?php the_content(); ?>
      </div>
    
    <?php endwhile; ?>
    <?php wp_reset_postdata(); // reset the query ?>

    This snippet should be good to display only posts from category 1. Adapt it to the category you’d like posts to be displayed from.

    I hope this helps 🙂
    – Maria Antonietta

    Dear Maria Antonietta Perna, thank you, it works! Can I limit the number of item?

    Adjust the code above like this:

    new WP_Query('cat=1&posts_per_page=3')

    This should limit the posts by category and number of posts.

    Perfect! Thank you very much!

    You’re very welcome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Home section blog’ is closed to new replies.