我正在尝试使用2个HTML模板(模式)进行WP查询。
我需要
我设法制作了第一个模板(A和B),但第二个模板(c和D)遇到了问题,因为它卡在了那个模板中,并用同一个模板循环其余的帖子。
我的代码如下:
<?php
$paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$custom_args = array(
\'post_type\' => \'causas_p\',
\'posts_per_page\' => 99,
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\',
\'paged\' => $paged
);
$custom_query = new WP_Query( $custom_args ); ?>
<?php if ( $custom_query->have_posts() ) : ?>
<?php $counter = 0; ?>
<!-- the loop -->
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<?php $counter ++; ?>
<div id="c<?php echo $counter;?>" class="col-lg-3 col-md-6 center col-padding">
<div class="max-height">
<div class="common-height clearfix" style="max-width:130px; margin:0 auto">
<div class="col-md-4 nopadding"><img class="vertical-middle" src="<?php bloginfo("template_url"); ?>/imagenes/hojita-home-1.png"></div>
<div class="col-md-8 nopadding"><h2 class="LunchBoxBold vertical-middle "><?php the_title(); ?></h2></div>
</div>
<p><?php the_field(\'contenido_causasp\');?></p>
<a class="boton" href="<?php the_permalink(); ?>">Únete</a>
</div>
</div>
<div class="col-lg-3 col-md-6 col-padding" style="background: url(\'<?php the_field(\'imagen_causa\');?>\') center center no-repeat; background-size: cover;">
</div>
<?php if ( $counter >= 2 ) {
break;
} ;?>
<?php endwhile; ?>
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<?php $counter ++; ?>
<div class="col-lg-3 col-md-6 col-padding" style="background: url(\'<?php the_field(\'imagen_causa\');?>\') center center no-repeat; background-size: cover;">
</div>
<div id="c<?php echo $counter;?>" class="col-lg-3 col-md-6 center col-padding">
<div class="max-height">
<div class="common-height clearfix" style="max-width:130px; margin:0 auto">
<div class="col-md-4 nopadding"><img class="vertical-middle" src="<?php bloginfo("template_url"); ?>/imagenes/hojita-home-1.png"></div>
<div class="col-md-8 nopadding"><h2 class="LunchBoxBold vertical-middle "><?php the_title(); ?></h2></div>
</div>
<p><?php the_field(\'contenido_causasp\');?></p>
<a class="boton" href="<?php the_permalink(); ?>">Únete</a>
</div>
</div>
<?php if ( $counter >= 4 ) {
$counter = 0;
break;
} ;?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
我怎样才能在其余的帖子中保持这两种模式?。。。对不起,我的英语不是我的母语。
提前感谢!
我运气不好:(
我没有任何运气,但我曾经更新过代码。不管怎样,它实际上是把同一个帖子显示了4次,然后转到另一个帖子,重复自己4次,然后转到另一个帖子,然后继续。
我不知道怎么解决这个问题。我认为“if”语句正在重置循环:/。我不知道,请帮忙。
“causas\\u p”,“posts\\u per\\u page”=>99,“order”=>“ASC”,“orderby”=>“menu\\u order”,“paged”=>$paged)$custom\\u query=新的WP\\u查询($custom\\u args);?>have\\u posts()):?>have\\u posts()):$custom\\u query->the\\u post();?>/imagenes/hojita-home-1。png“>
“>Únete”)居中不重复;背景尺寸:封面;”>
<?php ( $counter % 4 == 1 ) ;?>
<div id="c2" class="col-lg-3 col-md-6 center col-padding">
<div class="max-height">
<div class="common-height clearfix" style="max-width:130px; margin:0 auto">
<div class="col-md-4 nopadding"><img class="vertical-middle" src="<?php bloginfo("template_url"); ?>/imagenes/hojita-home-1.png"></div>
<div class="col-md-8 nopadding"><h2 class="LunchBoxBold vertical-middle "><?php the_title(); ?></h2></div>
</div>
<p><?php the_field(\'contenido_causasp\');?></p>
<a class="boton" href="<?php the_permalink(); ?>">Únete</a>
</div>
</div>
<div class="col-lg-3 col-md-6 col-padding" style="background: url(\'<?php the_field(\'imagen_causa\');?>\') center center no-repeat; background-size: cover;">
</div>
<?php if( $counter % 4 == 2 ) ;?>
<div class="col-lg-3 col-md-6 col-padding" style="background: url(\'<?php the_field(\'imagen_causa\');?>\') center center no-repeat; background-size: cover;">
</div>
<div id="c3" class="col-lg-3 col-md-6 center col-padding">
<div class="max-height">
<div class="common-height clearfix" style="max-width:130px; margin:0 auto">
<div class="col-md-4 nopadding"><img class="vertical-middle" src="<?php bloginfo("template_url"); ?>/imagenes/hojita-home-1.png"></div>
<div class="col-md-8 nopadding"><h2 class="LunchBoxBold vertical-middle "><?php the_title(); ?></h2></div>
</div>
<p><?php the_field(\'contenido_causasp\');?></p>
<a class="boton" href="<?php the_permalink(); ?>">Únete</a>
</div>
</div>
<?php if( $counter % 4 == 3 ) ;?>
<div class="col-lg-3 col-md-6 col-padding" style="background: url(\'<?php the_field(\'imagen_causa\');?>\') center center no-repeat; background-size: cover;">
</div>
<div id="c3" class="col-lg-3 col-md-6 center col-padding">
<div class="max-height">
<div class="common-height clearfix" style="max-width:130px; margin:0 auto">
<div class="col-md-4 nopadding"><img class="vertical-middle" src="<?php bloginfo("template_url"); ?>/imagenes/hojita-home-1.png"></div>
<div class="col-md-8 nopadding"><h2 class="LunchBoxBold vertical-middle "><?php the_title(); ?></h2></div>
</div>
<p><?php the_field(\'contenido_causasp\');?></p>
<a class="boton" href="<?php the_permalink(); ?>">Únete</a>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php if ( $counter >= 4 ) {
$counter = 0;
} ;?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>