我的wordpress网站有两种帖子类型 - 团队成员帖子类型和项目帖子类型。我想制作一个交替的无序列表,显示每种帖子类型的缩略图和标题,但似乎无法理解如何执行此操作。为清楚起见,我想要这样的输出:
我的代码如下。任何帮助将非常感谢!
<ul class="callout">
<?php $args = array('showposts' => 2, 'post_type' => 'team_member', 'orderby' => 'rand' );
$team_members = get_posts($args); ?>
<?php $args = array('showposts' => 2, 'post_type' => 'project');
$projects = get_posts($args); ?>
<?php foreach($projects as $post) :
setup_postdata( $post ); ?>
<?php $project_img = the_post_thumbnail_url( 'thumbnail' ); ?>
<?php echo $project_img; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php foreach($team_members as $post) :
setup_postdata( $post ); ?>
<?php $photo = get_field('team_member_photo'); ?>
<?php $image_size = 'thumbnail'; ?>
<?php $image = $photo['sizes'][$image_size]; ?>
<?php $name = get_the_title(); ?>
<?php $name = explode(" ", $name); ?>
<?php $name = array_shift($name); ?>
<?php endforeach;
wp_reset_postdata(); ?>
</ul> <!-- .callout -->