how to define count++ in wordpress php?

Solution:

$count is never defined…It’s up to you to define it. For example:

$count = 0;
foreach ( $recent_posts as $post ) {

That said, you’re never even using the value of $count…so it appears as if you could remove it altogether.

Another thing to note is that if you were to use a WP_Query instead of get_posts(), you would have access to a $current_post property for this purpose, without having to manually set up a counter.