Think about what is happening.
You run the_post();
which sets $post
to the first post in the Loop, but you don’t use that post if your sidebar is active. Then the Loop continues and $post
gets set to the second post in the Loop. You’ve lost your first post.
I don’t see why that first sidebar needs to be inside the Loop. You only need to be inside the have_posts
part to run the code when “the loop is active”. Something like this is what it seems you are going for:
if (have_posts()) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$i=1;
if ( is_active_sidebar('post_widget_area') && $i==1 ) {
dynamic_sidebar('post_widget_area');
}
while (have_posts()) {
the_post();
the_title();
the_excerpt();
if($i==3) {
get_sidebar('bottom');
}
$i++;
}
if($i<4) {
get_sidebar('bottom');
}
}
Sorry. I had to edit that code into something readable just to tell what was happening at all.
While I did not make this change in the code, you don’t need $i
. $wp_query->current_post
has the same information already, though it starts with 0
not 1
.