【发布时间】:2016-09-16 01:47:55
【问题描述】:
我有一个回显大约 10 个项目的页面。我希望它们在悬停时都有不同的背景图像。
我猜我需要在我的<head> 标记中添加我的循环,以便我可以应用背景图片。
这是我的循环:
<?php
// get background images for the services page
$post = get_field('related_services');
if( $posts ): ?>
<style>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
.sector-box[style]::after {
background-image: url("<?php echo get_template_directory_uri(); ?>/images/creative-bg-hover.jpg");
color:#<?php the_field( 'colour' ); ?>;
}
<?php endforeach; ?>
</style>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
我不能让它为每个人都呼应一种风格..
我还需要为每个盒子应用一个 ID 吗?以便它知道将背景图像应用到哪个框?
这是我的html:
<?php
$posts = get_field('related_services');
if( $posts ): ?>
<div class="container">
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<div class="sector-box reveal" style="background-color:<?php the_field( 'colour' ); ?>;">
<div class="sector-title">
<a href="<?php the_permalink(); ?>"><?php the_title( '' ); ?></a>
</div>
</div>
<!--Close Single Service box-->
<?php endforeach; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<!--Close Service Sector Boxes-->
【问题讨论】:
标签: php html css wordpress advanced-custom-fields