I have a Wordpress site that uses images to replace category text. It is configured for post-divs (indentation: 20% 0, for consistent sensitive height). Then has an absolute div, the vertical / horizontal upper limit of that div.
HTML
<div class="indx-img" style="background-image:url('...');">
<?php
$testStyle = "";
if(has_category( 'update' ) || has_category( 'uncategorized' )) {
$testStyle = "style=\"background-image:url('".get_bloginfo('template_directory')."/img/logo.png')\"";
} elseif(has_category( 'event' )) {
$testStyle = "style=\"background-image:url('".get_bloginfo('template_directory')."/img/logo.png')\"";
}
?>
<div class="test" <?php echo $testStyle; ?>></div>
</div>
CSS
.indx-img {
position: relative;
padding: 20% 0;
}
.test {
position: absolute;
left: 50%;
margin-left: -5em;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
height: 10em;
width: 10em;
}
This laid the background image for the test. The problem with this is that if it has more than one category, only one is displayed.
Ideally, I want the div created in the "test" for each category applied to the message to be assigned an image category aligned next to each other.
source
share