madeinthearcade
2/23/2017 - 10:17 AM

Create custom field to assign feature image to a post category and display it

Create custom field to assign feature image to a post category and display it

	<section class="banner-container">
		<ul>
			<?php 
			// vars
			$queried_object = get_queried_object(); 
			$taxonomy = $queried_object->taxonomy;
			$term_id = $queried_object->term_id;  

			// load thumbnail for this taxonomy term (term object)
			$thumbnail = get_field('static_banner', $queried_object);

			// load thumbnail for this taxonomy term (term string)
			$thumbnail = get_field('static_banner', $taxonomy . '_' . $term_id);
			?>

			<?php
				if(!empty($thumbnail)) {
					echo '<li style="background-image:url(' . $thumbnail['url'] . ')">';
					echo '<div class="bannertext">';
					echo '<h2 class="bannertitle">' .single_cat_title('',false) . '</h2>';
					echo category_description();
					echo '</div>';
					echo '</li>';
				} else {
					echo '<li style="background:#1d3a8e;">';
					echo '<div class="bannertext">';
					echo '<h2 class="bannertitle">' .single_cat_title('',false) . '</h2>';
					echo category_description();
					echo '</div>';
					echo '</li>';
				}
			?>
		</ul>
		<div class="usp-container">
			<div class="container">
				<div class="row">
					<div class="col-md-4">
						<div class="usp-box">
							<i class="fa fa-check" aria-hidden="true"></i> High quality products &amp; services
						</div>
					</div>
					<div class="col-md-4">
						<div class="usp-box">
							<i class="fa fa-check" aria-hidden="true"></i> We adapt to your business needs
						</div>
					</div>
					<div class="col-md-4">
						<div class="usp-box">
							<i class="fa fa-check" aria-hidden="true"></i> Delivery of 24/7 support
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>