我使用以下代码来显示特定联盟的总年数,但每年显示1。如何显示foreach循环中的元素总数?
例如,西班牙甲级联赛已经三年,但它显示的1,1,1代替3
我已经使用count($object);
和sizeof($object);
但没有得到想要的结果。
这里是我的代码:
<div class=" reds clearfix"; style="width: 50%;">
<ul id="test">
<!-- the loop -->
<?php while ($fixture_query->have_posts()) : $fixture_query->the_post(); ?>
<?php
$champion_team = get_post_meta(get_the_ID(), 'football_league_team_name', true);
$terms_competition = get_the_terms(get_the_ID(), 'competition');
$terms_session = get_the_terms(get_the_ID(), 'session'); ?>
<?php foreach ($terms_session as $object) {?>
<li style="float: left; margin-right: 5px;"> <?php echo $object->name; ?></li>
<?php
//echo count($object); // output 2
echo sizeof($object);
// echo count($object->name);
?>
<?php } ?>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
</ul>
</div>
为什么标记为js? –
它也可以用js来解决。不是吗? –
您可能需要echo sizeof($ terms_session); ... –