Amy-Mir / global-templates / home-services.php
home-services.php
Raw
<?php

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

$services = $args;

$servicesLink = substr($link = get_page_link(93), 0, -1);

function formatUrl($str1, $str2, $sep='-', $query = '?service=') {
    $res = strtolower($str2);
    $res = preg_replace('/[^[:alnum:]]/', ' ', $res);
    $res = preg_replace('/[[:space:]]+/', $sep, $res);
    return trim($str1, $sep) . $query . $res;
}

?>

<div id="slider__holder" class="container">
	<div id="slider" class="cardsWrapper__scroll">
		<div id="slider__items" class="cardsWrapper__hs">
		<?php 
			foreach($services as $index => $service):
				$urlBase = $servicesLink;
				$formatedUrl = formatUrl($urlBase, $service['service_title']);

				if( $index !== (sizeof($services) - 1)):
				get_template_part( 'loop-templates/cards', 'services', array(
					'title' => $service['service_title'],
					'img' => $service['service_cover'],
					'link' => $formatedUrl,
					'isLast' => false
				));
				else:
				get_template_part( 'loop-templates/cards', 'services', array(
					'title' => 'Utforsk mer',
					'img' => $service['service_cover'],
					'link' => $servicesLink,
					'isLast' => true
				));
				endif;
			endforeach;
		?>
		</div>
	</div>
</div>