This repository has been archived on 2022-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
Oldphaloskepsis/taxonomy-company.php
Ben Goldsworthy df05493b43 v1.0
2017-01-12 23:13:02 +00:00

143 lines
6.2 KiB
PHP

<?php
/**
* The template for displaying archive pages
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
* new template file for each one. For example, tag.php (Tag archives),
* category.php (Category archives), author.php (Author archives), etc.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
get_header(); ?>
<?php
$i = 0;
function withinDates($jSDate, $jEDate) {
//$endYear = date( "Y" );
$endDate = strtotime(date('Y-m-d'));
$startDate = strtotime("2015-01-01");
$jSDate = strtotime($jSDate);
if ($jEDate) {
$jEDate = strtotime($jEDate);
$jEDate = ($jEDate < $endDate) ? $jEDate : $endDate;
} else $jEDate = strtotime(date('Y-m-d'));
return (($jSDate < $endDate) && ($jEDate > $startDate));
}
$company = get_queried_object();
$args= array(
'post_type' => array( 'job' ),
'tax_query' => array(
array(
'taxonomy' => 'company',
'field' => 'slug',
'terms' => $company->name,
),
),
'posts_per_page' => -1
);
$loop = new WP_Query( $args )
?>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['timeline']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('timeline');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Type' });
dataTable.addColumn({ type: 'string', id: 'Job Title' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
<?php
while ( $loop->have_posts() ) : $loop->the_post();
if (withinDates(get_the_date(), get_post_meta(get_the_ID(), 'end-date', true))) {
$companies = wp_get_object_terms(get_the_ID(), 'company');
$i = 0;
$currSizeOf = -1;
foreach ($companies as $company) {
if (sizeof(get_ancestors($company->term_id, 'company')) > $currSizeOf) {
$currSizeOf = sizeof(get_ancestors($company->term_id, 'company'));
$lowestDepthCompany = $i++;
}
}
$title = html_entity_decode(get_the_title());
$start = get_the_date();
$end = (!get_post_meta(get_the_ID(), 'end-date', true)) ? date('D M d Y H:i:s O') : get_post_meta(get_the_ID(), 'end-date', true);
echo "[ '{$companies[$lowestDepthCompany]->name}', '$title', new Date('$start'), new Date('$end') ],\n";
}
endwhile;
?>
]);
chart.draw(dataTable);
var realheight=parseInt($("#timeline div:first-child div:first-child div:first-child div svg").attr( "height"))+50;
options.height=realheight;
//$("#timeline").attr("height", realHeight);
chart.draw(dataTable, options);
}
</script>
<div id="primary" class="content-area">
<main id="company-main" class="site-main" role="main">
<header class="page-header">
<?php
echo "<h1 id=\"page-title\">".get_queried_object()->name."</h1>";
the_archive_description( '<div class="taxonomy-description entry-content">', '</div>' );
?>
</header><!-- .page-header -->
<div class="row">
<div id="timeline" class="col-10 col-m-9"><img class="loading" src="/wp-content/uploads/2016/12/ajax-loader.gif"></div>
<div class="index col-2 col-m-3" id="companies-grid-small">
<h2 class="subheading">Children</h2>
<ul class="row">
<?php
$children = apply_filters("taxonomy-images-get-terms", "", array('having_images' => false, 'taxonomy' => 'company', 'term_args' => array('child_of' => get_queried_object()->term_id)));
foreach ( (array) $children as $child ) {
$imgURL = wp_get_attachment_image_src($child->image_id, 'detail')[0];
$colour = get_term_meta($child->term_id, 'color', true);
$colour = ($colour != "") ? $colour : "var(--light)";
echo "<a href=\"".esc_url(get_term_link($child, $child->taxonomy ))."\"><li class=\"col-12\" style=\"background-image: url(".strtok($imgURL, '?')."); background-color: ".$colour.";\"></li></a>";
}
?>
</ul>
</div>
</div>
<?php
$pageOrder = array( 'post', 'website', 'program', 'writing', 'video', 'other', 'qualification', 'award');
foreach ($pageOrder as $currSec) {
$args['post_type'] = array( $currSec );
$args['posts_per_page'] = 4;
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
echo "<div class=\"col-10 col-m-9\">";
echo "<h2 class=\"subheading\">".ucwords($currSec)."s <a href=\"/$currSec?company=".get_queried_object()->slug."\">View all ".$loop->post_count."</a></h2>";
echo "<div class=\"index\">";
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
echo "</div>";
echo "</div>";
endif;
}
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php //get_sidebar(); ?>
<?php get_footer(); ?>