I have a 'relationship' custom field that allows you to select multiple values and display them via
<?php $post_objects = get_field('field');
if($post_objects!=''){ ?>
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>,
</a>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
This works for now but is not very pretty as it returns the values as "Value, Value, Value,". What I would like it to output is...
1 Value = "Value"
2 Values = "Value & Value"
3 or more Values = "Value, Value & Value"
"
I have a 'relationship' custom field that allows you to select multiple values and display them via
<?php $post_objects = get_field('field');
if($post_objects!=''){ ?>
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>,
</a>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
This works for now but is not very pretty as it returns the values as "Value, Value, Value,". What I would like it to output is...
1 Value = "Value"
2 Values = "Value & Value"
3 or more Values = "Value, Value & Value"
"
Share Improve this question asked Dec 21, 2013 at 1:48 SBMSBM 721 silver badge7 bronze badges2 Answers
Reset to default 0Try to grab the output and echo together.
<?php $post_objects = get_field('field');
if($post_objects!='') :
$value = array(); ?>
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<?php $values[] = '<a href="'. get_permalink() .'">'. the_title('','',false) .'</a>'; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php echo join( ', ', $values); ?>
You can use the number_format function of PHP.
You will get something like 2,500
<div>
<?php if (get_field('events_price_yen')) { ?>
<p>
<?php $english_format_number = number_format(get_field('events_price_yen'));
echo $english_format_number; ?>
</p>
<?php }; ?>
</div>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340941a4623322.html
评论列表(0条)