background-image
別の要素にテキスト文字列が含まれているかどうかに応じて、次のコード例を組み合わせて css 値を変更しています。
別の要素がページに複数回表示されるため (wordpress ポスト メタ データ)、この jQuery は基準が満たされるたびに実行する必要があります。
$(window).load(function(){
if ($(".postmetadata").contains("Seattle")) {
$(this).closest(".boxy").find(".storyNoIMG")
.addClass('.seattleIMG');
} else {
}
});
これが私が使用している2番目の例です:
var imageURL = "images/seattle.png";
if ($(".postmetadata").contains("Seattle")) {
$(this).closest(".boxy").find(".storyNoIMG")
.css("background-image","url(" + "images/seattle.png" + ")");
}
html コンテキストは次のとおりです。
<div class="boxy">
<div class="boxGrad">
<div class="postmetadata">
<?php echo time_ago(); ?> •
<?php the_category(' • ') ?>
</div>
<div class="articleTitle">
<a><?php the_title(); ?></a>
</div>
<div class="exPand">
</div>
<div class="rightCtrls">
<!-- heart + -->
<?php echo getPostLikeLink(get_the_ID());?>
<div class="imageGlass">
<a href="#">
<img src="<?php echo get_template_directory_uri(); ?>/media/imageMag-02.png">
</a>
</div>
</div>
</div> <!-- end post right controls -->
<div class="ajaxBoxLoadSource">
<iframe class="ajaxIframe"></iframe>
</div>
<div class="storyNoImg"></div>
<div class="articleImageThumb">
<a href="<?php if(get_post_meta($post->ID, "url", true)) echo get_post_meta($post->ID, "url", true); else the_permalink(); ?>" rel="<?php the_ID(); ?>">
<?php echo get_the_post_thumbnail($page->ID, 'original'); ?>
</a>
</div>
</div> <!-- end boxy -->