<?php
/*
Template Name: Single Job Page Template
*/

get_header();
$sv_job_meta = get_post_custom(); ?>

	<div id="primary" class="job-page">

		<?php while ( have_posts() ) : the_post(); ?>

			<div class="title-wrap">
				<span class="job-color" style="background-color: #<?php echo $sv_job_meta['sv_job_color'][0]; ?>"></span>
				<h2 class="company-name"><?php the_title(); ?></h2>
				<?php if ( isset( $sv_job_meta['sv_job_title'][0] ) ) { ?>
					<h3 class="job-title">
						<?php echo $sv_job_meta['sv_job_title'][0]; ?>
					</h3>
				<?php } ?>
			</div>


		<div id="content" role="main">
		<article id="single-job-listing">
				<div class="job-description">
					<?php the_content(); ?>
				</div>
		</article><!-- #single-job-listing -->
	</div><!-- #content -->
</div><!-- #primary -->

		<div id="job-meta" class="widget-area">
			<ul>
				<li class="company-color">
					<span <?php
					if ( isset( $sv_job_meta['sv_job_color'][0] ) )
					echo 'style="background: ' . $sv_job_meta[ 'sv_job_color' ][0] . ';"'?>></span>
				</li>
				<li class="company-logo">
					<?php if ( '' != get_the_post_thumbnail() ) the_post_thumbnail(); ?>
				</li>
				<?php if ( isset( $sv_job_meta['sv_job_start_date'][0] ) ) { ?>
				<li>
					<h3>Start date</h3>
					<?php echo $sv_job_meta['sv_job_start_date'][0]; ?>
				</li>
				<?php } ?>
				<?php if ( isset( $sv_job_meta['sv_job_end_date'][0] ) ) { ?>
				<li class="end-date-title">
					<h3>End date</h3>
					<?php echo $sv_job_meta['sv_job_end_date'][0]; ?>
				</li>
				<?php } ?>
			</ul>
		</div><!-- #resume-job-left-bar -->

		<?php endwhile; // end of the loop. ?>


		<div id="skills" class="widget-area" role="complementary">

				<aside id="archives" class="widget">
					<ul>
					<?php
						// This should be working better
						global $post;
						$terms = wp_get_post_terms( $post->ID, 'sv_respons' );

						$terms_ordred = array();
						foreach ( $terms as $term )
							$terms_ordred[$term->parent][$term->term_id] = $term->name;


						foreach ( $terms_ordred[0] as $parent => $name ) {
							echo '<li>';
							echo $name;
							echo '<ul>';
							$child_terms = $terms_ordred[$parent];
							foreach ( $child_terms as $child_name ) {
								echo '<li>';
								echo $child_name;
								echo '</li>';
							}
							echo '</ul>';
							echo '</li>';
						}

					?>
					</ul>
				</aside>
		</div><!-- #secondary .widget-area --><?php get_footer(); ?>