I've got a custom field on posts called number
.
On the front-end in category.php, I need to total up the value of all posts in the current category that have number
.
So for example, if the current category had 3 posts, and in each post the number
values were 1
, 5
and 10
respectively, then on the front-end it needs to display the total 16
.
I'm not entirely sure where to start with this.
The loop I have at the moment:
<?php if ( have_posts() ) : ?>
<h1><?php printf( __( 'Category Archives: %s', 'twentythirteen' ), single_cat_title( '', false ) ); ?></h1>
<p></p>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php // ?>
<?php endif; ?>
Any help is appreciated.
Thanks everyone. There was a lot there that helped me arrive at this solution (and a little help from Google):
The key was knowing to increment a variable += as @rnevius suggested, which I didn't know about.