1 回答
TA贡献1802条经验 获得超6个赞
一个选项是像这样拆分查询:
<?php
/*MOSTRA NEWS CPT ALLENAMENTO*/
$query_mostra_cpt_allenamento = array(
'post_type' => 'news-allenamento',
'posts_per_page' => 1, // return only the first post
'orderby' => 'meta_value',
'order' => 'ASC',
'no_found_rows' => true,
);
/*MOSTRA NEWS CPT ALLENAMENTO*/
$query_mostra_cpt_allenamento_after = array(
'post_type' => 'news-allenamento',
'posts_per_page' => 3,
'offset' => 1,// start from the second post
'orderby' => 'meta_value',
'order' => 'ASC',
'no_found_rows' => true,
);
$res_cpt_allenamento = new WP_Query( $query_mostra_cpt_allenamento );
$res_cpt_allenamento_after = new WP_Query( $query_mostra_cpt_allenamento_after ); ?>
<div style="padding-top: 30px;" class="row">
<?php if( $res_cpt_allenamento->have_posts() ) : ?>
<?php while( $res_cpt_allenamento->have_posts() ) : $res_cpt_allenamento->the_post(); ?>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="view">
...
</div>
</div>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata();
?>
<?php if( $res_cpt_allenamento_after->have_posts() ) : ?>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="container-fluid">
<div class="row">
<?php while( $res_cpt_allenamento_after->have_posts() ) : $res_cpt_allenamento_after->the_post(); ?>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="view">
...
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php endif;
wp_reset_postdata();
?>
</div>
另一种选择是在你的 while 循环中添加一个计数器,检查你在哪里并采取相应的行动:
<?php
/*MOSTRA NEWS CPT ALLENAMENTO*/
$query_mostra_cpt_allenamento = array(
'post_type' => 'news-allenamento',
'posts_per_page' => 4,
'orderby' => 'meta_value',
'order' => 'ASC',
);
$res_cpt_allenamento = new WP_Query( $query_mostra_cpt_allenamento );
$i = 0;
if( $res_cpt_allenamento->have_posts() ) : ?>
<div style="padding-top: 30px;" class="row">
<?php while( $res_cpt_allenamento->have_posts() ) : $res_cpt_allenamento->the_post(); $i++; ?>
<?php if ($i < 2) : ?>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="view">
...
</div>
</div>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="container-fluid">
<div class="row">
<?php else : ?>
<div style="padding-right: 0px;padding-left: 0px;border: 1px solid #fff" class="col-md-6">
<div class="view">
...
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
<?php endif;
wp_reset_postdata();
?>
不确定结构,但这是逻辑
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报