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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…