因此,正如标题所说,我正试图从一个类别向缩略图中添加一个div类。我正在尝试使用此代码:
if (in_category( \'Expired\' )) : ?><div class="expire">
这是我试图添加到的单个邮政编码:
<?php
if(has_post_thumbnail()) {
the_post_thumbnail(
array($theme->get_option(\'featured_image_width_single\'), $theme->get_option(\'featured_image_height_single\')),
array("class" => $theme->get_option(\'featured_image_position_single\') . " featured_image")
);
}
?>
这是我在样式表中创建的div类:
.expire {
position: absolute;
bottom: 10px;
background:url(images/sample-expired.png) no-repeat ;
width: 100px;
height:60px;
text-align: center;
padding: 4px;
border-radius: 10px;
left: 2px;
}
你知道我应该把这个贴在代码的什么地方吗?或者有什么帮助来实现这一点?感谢堆
SO网友:hamdirizal
要将缩略图包装起来,我会这样做:
第一创建过期类字符串
$expire_class = in_category(\'expired\') ? \'expire\' : \'\';
然后,用以下内容包装您的帖子缩略图代码:
<div class=\'<?php echo $expire_class; ?>\' >
[put your thumbnail code here]
</div>
看起来是这样的:
<?php
$expire_class = in_category(\'expired\') ? \'expire\' : \'\';
if(has_post_thumbnail()) {
?><a href="<?php the_permalink(); ?>"><div class=\'<?php echo $expire_class; ?>\' > <?php the_post_thumbnail(
array($theme->get_option(\'featured_image_width\'), $theme->get_option(\'featured_image_height\')),
array("class" => $theme->get_option(\'featured_image_position\') . " featured_image")
); ?></div></a><?php
}
?>