Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
6834ec5ce7
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
121 lines (100 sloc) 4.96 KB
<?php
/*
Template Name: Course Subjects
*/
get_header(); ?>
<?php //Grabs most parent page's featured image for background of title.
while (have_posts()) : the_post();
$parent = array_reverse(get_post_ancestors(get_the_ID()));
$first_parent = get_page($parent[0]);
$first_parent_Id = $first_parent->ID;
$url = wp_get_attachment_image_src( get_post_thumbnail_id($first_parent_Id), 'full');
endwhile?>
<?php include(get_template_directory().'/inc/sidebar-check.php')?>
<div id="page-page">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-<?php echo (is_active_sidebar( $sidebar )?9:12); ?>">
<div id="primary" class="content-area subpage">
<main id="main" class="site-main" role="main">
<?php get_template_part( 'content', 'page' ); ?>
<?php
// Alphabet array
$alpharay = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
// Letter navigation
echo '<ul class="letter-list clearfix">';
foreach($alpharay as $letter) {
echo '<li><a href="#letter-' . $letter . '">' . $letter . '</a></li>';
};
echo '</ul>';
// Counter for proper .row and .span placement
$colcount = 0;
// Course Subject Query args
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'subjects',
'pad_counts' => false
);
// Subject Taxonomy array
$subject_list = get_categories($args);
// Start by looping through the alphabet array
foreach( $alpharay as $letter ) {
$letter_exists = 0;
// Determine whether there are subjects that start with current letter
foreach($subject_list as $subject) {
if(strpos($subject->name, $letter) === 0) {
$letter_exists = 1;
};
};
// Perform if subjects exist starting with current letter
if($letter_exists) {
// Create small list for each letter
if($colcount) {
echo '<div class="col-sm-6 alph-subj-list columns" id="letter-' . $letter . '">';
echo '<h2>' . $letter . '</h2>';
echo '<ul class="course-alpha-list">';
foreach( $subject_list as $subject ) {
if(strpos($subject->name, $letter) === 0) {
$subject_link = get_home_url() . '/graduate-courses/' . $subject->slug;
echo '<li><a href="' . $subject_link . '">' . $subject->description . ' (' . $subject->name . ')</a></li>';
};
};
echo '</ul>';
echo '</div>';
echo '</div>';
$colcount = 0;
} else {
echo '<div class="row">';
echo '<div class="col-sm-6 alph-subj-list columns" id="letter-' . $letter . '">';
echo '<h2>' . $letter . '</h2>';
echo '<ul class="course-alpha-list">';
foreach( $subject_list as $subject ) {
if(strpos($subject->name, $letter) === 0) {
$subject_link = get_home_url() . '/graduate-courses/' . $subject->slug;
echo '<li><a href="' . $subject_link . '">' . $subject->description . ' (' . $subject->name . ')</a></li>';
};
};
echo '</ul>';
echo '</div>';
$colcount++;
};
};
};
?>
</main>
</div>
</div>
<?php include(get_template_directory().'/inc/sidebar-if-active.php')?>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>