I’m working on WordPress where I have following code to get posts within loop.
<?php
$posts = $woo_options['woo_latest_entries'];
query_posts('post_type=post&category_name=company');
if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++;
?>
/// Post Content Goes Here //
<?php endwhile; endif; ?>
Which Output posts inside Loops something like this…
Post Goes Here ....
Other Post Goes Here ....
Another Post Goes Here ....
.....
What I want is to print current posts index number within loop. Example
1. Post Goes Here ....
2. Other Post Goes Here ....
3. Another Post Goes Here ....
.....
How Can I Achieve This ? Thanks.
EDIT
Ohh ! I can do it this way ..
<?php
echo $wp_query->current_post +1;
?>
Is there any other / Better way ?
Actually I want to assign ID’s as per post index !
Here’s your code that I modified.
<?php
global $wp_query;
$posts = $woo_options['woo_latest_entries'];
query_posts('post_type=post&category_name=company');
if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++;
$index = $wp_query->current_post + 1;
?>
<div id="my_post_<?php echo $index; ?>">
<!-- Post Content Goes Here -->
</div>
<?php endwhile; endif; ?>