Wordpress自定义循环
需要帮助才能创建如下循环: 具有两种箭头样式(左箭头和右箭头) 1) 带有左箭头的项目2)带有左箭头的项目 3) 带有右箭头的项目4)带有右箭头的项目 5) 带有左箭头的项目6)带有左箭头的项目 等等 我的循环现在:Wordpress自定义循环,wordpress,foreach,while-loop,Wordpress,Foreach,While Loop,需要帮助才能创建如下循环: 具有两种箭头样式(左箭头和右箭头) 1) 带有左箭头的项目2)带有左箭头的项目 3) 带有右箭头的项目4)带有右箭头的项目 5) 带有左箭头的项目6)带有左箭头的项目 等等 我的循环现在: <?php $services = get_posts(array( 'meta_query' => array( arr
<?php
$services = get_posts(array(
'meta_query' => array(
array(
'key' => 'enable_service_in_homepage',
'compare' => '==',
'value' => '1'
)
)
));
if( $services ):
?>
<?php foreach( $services as $post ): setup_postdata( $post ) ?>
<div class="col-sm-6 nopadding">
<div class="item item-left">
<div class="col-sm-6 nopadding hidden-xs">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(700, 500) ); ?></a>
<div class="arrow-left"></div>
</div>
<div class="col-md-6 nopadding">
<div class="content">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_trim_words( get_the_content(), 35, '...' ); ?></p>
<a href="<?php the_permalink(); ?>" class="service-button"><?php echo __('ƏTRAFLI','altus'); ?></a>
</div>
</div>
</div>
</div>
<!-- Start right arrow -->
<div class="col-sm-6 nopadding">
<div class="item item-right">
<div class="col-md-6 nopadding">
<div class="content">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_trim_words( get_the_content(), 35, '...' ); ?></p>
<a href="<?php the_permalink(); ?>" class="service-button"><?php echo __('ƏTRAFLI','altus'); ?></a>
</div>
</div>
<div class="col-sm-6 nopadding hidden-xs">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(700, 500) ); ?></a>
<div class="arrow-right"></div>
</div>
</div>
</div>
<!-- End right arrow -->
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
也许有一种更干净的方法可以做到这一点,但您可以通过以下方式来实现:
那么,问题是什么?对不起,我的英语不好。我需要帮助,使布局像在图片中,在我的循环现在只有左箭头,有评论在哪里开始另一个布局与右箭头。需要这样的表格:1)带有左箭头的项目2)带有左箭头的项目3)带有右箭头的项目4)带有右箭头的项目5)带有左箭头的项目6)带有左箭头的项目我建议您省略代码的后半部分(开始右箭头注释及以后),并删除“向左箭头”从代码的顶部初始化,并将其替换为交替打印“箭头向左”和“箭头向右”的代码。你想知道如何替换吗?请添加一个小例子,我想需要第二个布局,比如我的块和注释,每第二行图像在右边,内容在左边
<?php
$services = get_posts(array(
'meta_query' => array(
array(
'key' => 'enable_service_in_homepage',
'compare' => '==',
'value' => '1'
)
)
));
?>
<?php if( $services ): ?>
<?php $services_chunked = array_chunk( $services, 2 ); ?>
<?php foreach( $services_chunked as $key => $posts ): ?>
<?php $alignment = $key % 2 ? "left" : "right"; ?>
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<div class="col-sm-6 nopadding">
<div class="item item-<?= $alignment ?>">
<div class="col-sm-6 nopadding hidden-xs">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(700, 500) ); ?></a>
<div class="arrow-<?= $alignment ?>"></div>
</div>
<div class="col-md-6 nopadding">
<div class="content">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_trim_words( get_the_content(), 35, '...' ); ?></p>
<a href="<?php the_permalink(); ?>" class="service-button">Altus</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endforeach; ?>
<?php endif; ?>