私はワードプレスのテーマを使用していますが、特定の変数の値が偶数または奇数の場合、php を使用して 2 つのブロックの css を変更したいと考えています。
これは私のコードです:
<?php
$i = 0;
while ( have_posts() ) {
// Override
if(($i % 2) == 1) { ?>
<style type="text/css">
.grid-box-img {
width: 54%;
float: left;
}
.entry-head {
width: 56%;
background-color: #fff;
position: absolute;
z-index: 10;
margin-left: 43%;
margin-top: 27%;
}
</style>
<?php
}
else { ?>
<style type="text/css">
.grid-box-img {
width: 54%;
float: right;
}
.entry-head {
width: 56%;
background-color: #fff;
position: absolute;
z-index: 10;
margin-top: 27%;
}
</style>
<?php
}
$i++;
the_post();
} ?>
しかし、残念ながらうまくいきません... 最後の値の CSS だけを適用します。
どうやってやるの ?ありがとうございました :)