srjm
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Fixing WordPress
In reply to: Show post numberUpdate on that:
function Get_Post_Number($postID){ $temp_query = $wp_query; $postNumberQuery = new WP_Query('orderby=date&posts_per_page=-1'); $counter = 1; $postCount = 0; if($postNumberQuery->have_posts()) : while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post(); if ($postID == get_the_ID()){ $postCount = $counter; } else { $counter++; } endwhile; endif; wp_reset_query(); $wp_query = $temp_query; return $postCount; }
will work inside your main loop:
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); $currentID = get_the_ID(); $currentNumber = Get_Post_Number($currentID);
etc. etc.
Also I’m deliberately ordering them so that the newest post is number 1 but I don’t think it would take much more to order them oldest first if that is what you wanted.Forum: Fixing WordPress
In reply to: Show post numberfunction Get_Post_Number($postID){ $postNumberQuery = new WP_Query('orderby=date&posts_per_page=-1'); $counter = 1; $postCount = 0; while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post(); if ($postID == get_the_ID()){ $postCount = $counter; echo("true"); } else { $counter++; } endwhile; return $postCount; }
I was looking for solutions for something similar but there isn’t a lot around in the way of actual answers…
This is just an idea to get started but unfortunately because it’s a second loop you can’t run it inside the main loop without it interfering (it overwrites the_post() global variable I’m guessing). I’ll be looking into running a loop inside a loop soon enough though.
Viewing 2 replies - 1 through 2 (of 2 total)