If you are showing list of latest post then here is the easier way of it in which you can add classes and DIV as per your wish.
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post', //Post type that you want to show
'posts_per_page' => 5, //No. of Pages to show
'offset' => 0, //excluding the latest post if any
'paged' => $paged //For Pagination
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>
<?php /*** Title of Post ***/ ?>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title();?></a></h3>
<?php /*** Title of Post ends ***/ ?>
<?php
/***** Thumbnail ******/
the_post_thumbnail(
array(120, 90),
array(
'class' => 'enter_class', //custom class for post thumbnail if any
'alt' => 'post thumbnail', //post thumbnail alternate title
'title' => 'my custom title' //Title of thumbnail
)
);
/******* Thumbnail Ends ********/
/*** Post contents/Description ***/
the_excerpt();
/*** Post contents/Description ends ***/
?>
<?php
endwhile;
UPDATE
If you want to add div on individual post then you need to add div inside while
loop.
If you want to wrap your every post in individual div then add div in while
loop in above mentioned code like this
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="enter_class_name">
<?php
//Rest of the code in while loop like title,description and thumbnail code will come here.
?>
</div>
NOTE Make sure you don't add DIV inside php tags (<?php ?>
). Specify your DIV outside php tags.
And you can also add DIV in parts of post also. For example if you want to add DIV to wrap thumbnail of every posta individually then you can also do that easily.
To do that you have to read all comments in code to understand what code is using to show thumbnail of post and simply wrap that code inside DIV. And your post thumbnail will be enclosed in separate DIV.
In my given code this piece of code inside while loop is responsible for showing post thumbnail
<?php
/***** Thumbnail ******/
the_post_thumbnail(
array(120, 90),
array(
'class' => 'enter_class', //custom class for post thumbnail if any
'alt' => 'post thumbnail', //post thumbnail alternate title
'title' => 'my custom title' //Title of thumbnail
)
);
/******* Thumbnail Ends ********/
And to wrap thumbnail inside div, just wrap this code inside div(outside php tags) like this
<div class="enter_class_name">
<?php
/***** Thumbnail ******/
the_post_thumbnail(
array(120, 90),
array(
'class' => 'enter_class', //custom class for post thumbnail if any
'alt' => 'post thumbnail', //post thumbnail alternate title
'title' => 'my custom title' //Title of thumbnail
)
);
/******* Thumbnail Ends ********/
?>
</div>
Like this you can also wrap your Title of post or Description of post in separate DIV just by enclosing their respective code in DIV.
BUT make sure to put all DIVs only inside while
loop. Only then your posts will get separate DIV.
And it is strongly recommended that you read all comments line attach to the code carefully to understand every line of code is performing what kind of action/activity. This info will help you to add DIV as per your need.