Add “showing posts x to x of y” in custom post type paginated loop

All query objects have a few built in vars that can help you display this. Assuming your custom query object is $query: The total number of posts across all pages is $query->found_posts The total number of posts for the current page is $query->post_count The current page number is $query->query_vars[‘paged’] The number of posts per page … Read more

Is it possible to reverse the order of a list of posts pulled from a loop?

Assuming you are refering to the code of this answer Taking the query from that answer $args = array( ‘category_name’ => ‘your-category-slug’, ‘posts_per_page’ => 3, ); $wpse_235685_query = new WP_Query( $args ); you would then, to reverse the order of your results, need to modify the query $posts object, like so $temp_posts = $wpse_235685_query->posts; // … Read more

Can I add generic numbering HTML classes to items as a loop runs?

You could use post_class within the loop. <?php post_class( ‘myclass-here’); ?> This will add the necessary HTML class=”” and WP defaults classes plus your new myclass-here class You could then use counters within the loop to add a unique suffix to your post class // Outside the loop initialize your counter $counter = 1; . … Read more

Loop counter style

You can use the Modulo Operator in PHP to check if the loop count is odd or even and then assign those elements a CSS class based on that. $class=”listpostsright”; if ($wp_query->current_post % 2 == 0) { $class=”listpostsleft”; } Things to note: In programming counting begins at 0, so this logic may look a bit … Read more