我有这个代码,因为我需要它来。。。但现在我需要添加一个post count,其中“____“是,在“海报”旁边,因此我可以根据显示的海报数量操纵css,例如:<div id="posters1">
或<div id="posters2">
或<div id="posters3">
, 等
我相信这可以用$post_count
或$found_posts
但我不知道该把它放在哪里,或者把海报移到哪里div
(即:回路内部?):
<div id="posters_ _ _ _">
<?php
$movieNumber = 1;
$today = date(\'Ymd\');
$posts = array (
\'post_type\' => \'movie\',
\'posts_per_page\' => -1,
);
$loop = new WP_Query( $posts );
while ( $loop->have_posts() ) : $loop->the_post();
$attachment_id=get_field(\'movie_poster\',$post->post_id);
$size = "poster"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size ); // url = $image[0], width = $image[1], height = $image[2];
echo \'<div class="poster"><a class="various" rel="movies" href="#fancy\' . $movieNumber++ . \'"><img src="\' . $image[0] . \'" /></a></div><!-- #poster -->\';
endwhile;
?>
</div><!-- #posters -->
最合适的回答,由SO网友:Michael 整理而成
重新排列代码并使用post_count
;示例:
<?php
$movieNumber = 1;
$today = date(\'Ymd\');
$posts = array (
\'post_type\' => \'movie\',
\'posts_per_page\' => -1,
);
$loop = new WP_Query( $posts ); ?>
<div id="posters<?php echo $loop->post_count; ?>">
<?php while ( $loop->have_posts() ) : $loop->the_post();
...etc...