【发布时间】:2018-08-26 18:25:50
【问题描述】:
尊敬的 PHP / Wordpress / 开发专家,
我已经构建了一个插件,具有自定义帖子类型和一些高级自定义字段。主要目标是列出我乐队中的成员,并附上照片和姓名。
你可以在这里看到它:http://www.lucky13.nl/test/
不过,我设法让一切都符合我的口味。我的乐队中有 5 个乐队成员,我已经添加了这些成员,但我只看到 4 个。第 5 个条目/帖子在哪里?我发现第一个添加的乐队成员没有显示。
我认为这与循环有关,并且数组没有列出所有项目?但我会把这个留给专家。我会很感激任何帮助!
我的代码:
<?php
/*
Plugin Name: VrolijkWebdesign - Bandmembers
Description: For a bandwebsite to show bandmembers.
*/
/* Start Adding Functions Below this Line */
/* NAME FUNCTION */
function new_section_1(){
$bandmembers = new WP_Query(array(
'post_type' => 'bandmembers'
));
while($bandmembers->have_posts()) : $bandmembers->the_post();
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<!-- START HTML -->
<div class="span2">
<figure class="snip1104">
<img src="<?php echo $image[0] ;?>" alt='sample33'/>
<figcaption>
<h5> <?php the_field('firstname'); ?> <span> <?php the_field('lastname'); ?>
</span></h5>
</figcaption>
<a href="#"></a>
</figure>
</div>
<!-- END HTML -->
<?php endif;
endwhile;
}
add_shortcode('band', 'new_section_1');
?>
【问题讨论】:
-
你应该添加
'status' => 'publish'否则草稿中的帖子会出现,'post_per_page' => -1 -
感谢一百万马克,这解决了我的问题!
标签: wordpress custom-post-type advanced-custom-fields