我是PHP新手。所以请耐心听我说。在WordPress主题中,我已经创建了一个自定义帖子类型(team),现在我希望在一个div中显示3个帖子标题,然后显示3个帖子中每个帖子的内容(在不同的div中),然后对每组3个帖子重复此操作,直到查询结束。
我的HTML看起来像这样,但是我不知道如何组装PHP。因此,如果有任何帮助,我们将不胜感激:
<div class="section-wrapper">
<div class="member-row row-1">
<div class="team-member member-1">
<h2><?php the_title(); ?></h2>
</div>
<div class="team-member member-2">
<h2><?php the_title(); ?></h2>
</div>
<div class="team-member member-3">
<h2><?php the_title(); ?></h2>
</div>
</div>
<div class="summary summary-1">
<?php
// display the_content() of each of the 3 posts I just queried
the_content();
?>
</div>
</div>
<div class="section-wrapper">
<div class="member-row row-2">
<div class="team-member member-4">
<h2><?php the_title(); ?></h2>
</div>
<div class="team-member member-5">
<h2><?php the_title(); ?></h2>
</div>
<div class="team-member member-6">
<h2><?php the_title(); ?></h2>
</div>
</div>
<div class="summary summary-2">
<?php
// display the_content() of each of the 3 posts I just queried
the_content();
?>
</div>
</div>发布于 2015-08-29 07:33:45
我会尝试更简单的html,但是如果你想使用它,你可以使用下面的代码。
<div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
'post_type' => 'team',
// choose other differentiating parameter, for example tag
'tag' => 'main'
);
// The Query
$query = new WP_Query( $args );
// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post();
?>
<div class="member-row row-1 <?php post_class(); ?>">
<div class="team-member member-1">
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php
endwhile; endif;
// Restore original Post Data
wp_reset_postdata();
?>
<?php
// WP_Query arguments
$args = array (
'post_type' => 'team',
// choose other differentiating parameter, for example tag
'tag' => 'main'
);
// The Query
$query = new WP_Query( $args );
// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post();
?>
<div class="summary <?php post_class() ?>">
<?php
// display the_content() of each of the 3 posts I just queried
the_content();
?>
</div>
<?php
endwhile; endif;
// Restore original Post Data
wp_reset_postdata();
?>
</div>
<div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
'post_type' => 'team',
// choose other differentiating parameter, for example tag
'tag' => 'seconday'
);
// The Query
$query = new WP_Query( $args );
// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post();
?>
<div class="member-row row-1 <?php post_class(); ?>">
<div class="team-member member-1">
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php
endwhile; endif;
// Restore original Post Data
wp_reset_postdata();
?>
<?php
// WP_Query arguments
$args = array (
'post_type' => 'team',
// choose other differentiating parameter, for example tag
'tag' => 'secondary'
);
// The Query
$query = new WP_Query( $args );
// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post();
?>
<div class="summary <?php post_class() ?>">
<?php
// display the_content() of each of the 3 posts I just queried
the_content();
?>
</div>
<?php
endwhile; endif;
// Restore original Post Data
wp_reset_postdata();
?>
</div>https://stackoverflow.com/questions/32211192
复制相似问题