How to add padding between posts

WordPress already generates class for each posts, you can use these classes using the post_class function.

Note: The function can be used either within the loop or by passing the $post_id

So you would have

<ul>
    <?php $the_query = new WP_Query( 'posts_per_page=5' ); ?>

    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

        <div id="post-<?php the_ID(); ?>" <?php post_class( 'post' ); ?>>
            <a href="https://wordpress.stackexchange.com/questions/250637/<?php the_permalink() ?>"><?php the_title(); ?></a>

            <?php the_excerpt(__('(moreā€¦)')); ?>
        </div>

    <?php
    endwhile;
    wp_reset_postdata();
    ?>
</ul>

Leave a Comment