Created
June 26, 2012 19:53
-
-
Save kimisgold/2998458 to your computer and use it in GitHub Desktop.
JDH Table of Contents template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: Archived Table of Contents | |
*/ | |
?> | |
<?php get_header(); ?> | |
<div class="front-page twelve columns offset-by-two omega"> | |
<?php /* This section is the introduction for the table of contents. It pulls the_content() from the Table of Contents page. That page also has custom meta values for the PDF and EPUB links. */ | |
if ( have_posts() ) : while ( have_posts() ) : the_post(); | |
the_content(); | |
$pdf_values = get_post_custom_values('pdf_url'); | |
$pdf_url = $pdf_values[0]; | |
$epub_values = get_post_custom_values('epub_url'); | |
$epub_url = $epub_values[0]; | |
?> | |
<div class="downloads"> | |
<p>Available for download</p> | |
<a href="<?php echo $pdf_url; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/pdf.png" alt="pdf download"></a> | |
<a href="<?php echo $epub_url; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/epub.png" alt="epub download"></a> | |
</div> | |
<?php endwhile; else: ?> | |
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p> | |
<?php endif; ?> | |
<?php /* This section checks the category for this page, which should be the issue number, and looks for all posts that fall under this issue and the "Introduction" category. */ ?> | |
<div class="introduction"> | |
<h2>Introductions</h2> | |
<?php if(has_category()): | |
$categories = get_the_category(); | |
$category = $categories[0]->term_id; | |
endif; | |
if ( is_user_logged_in() ) { | |
$args = array( 'numberposts' => 2, 'post_type' => 'introduction', 'cat' => $category, 'post_status' => 'publish,private,draft,inherit' ); | |
} else { | |
$args = array( 'numberposts' => 2, 'post_type' => 'introduction', 'cat' => $category ); | |
} | |
$lastposts = get_posts( $args ); | |
if(count($lastposts)==1): | |
$post = $lastposts[0]; ?> | |
<div class="solo eight columns offset-by-two"> | |
<h3><a href="<?php get_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<?php if(function_exists('coauthors')): ?> | |
<h4 class="author-name"><?php coauthors(',<br>'); ?></h4> | |
<?php else: ?> | |
<h4 class="author-name"><?php echo the_author_meta('first_name'); ?> <?php echo the_author_meta('last_name'); ?></h4> | |
<?php endif; ?> | |
<?php the_excerpt(); ?> | |
</div> | |
<?php else: | |
$i = 0; | |
foreach($lastposts as $post) : setup_postdata($post); ?> | |
<?php if($i == 0): ?> | |
<div class="intro-post six columns alpha"> | |
<?php else: ?> | |
<div class="intro-post six columns omega"> | |
<?php endif; ?> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<?php if(function_exists('coauthors')): ?> | |
<h4 class="author-name"><?php coauthors(',<br>'); ?></h4> | |
<?php else: ?> | |
<h4 class="author-name"><?php echo the_author_meta('first_name'); ?> <?php echo the_author_meta('last_name'); ?></h4> | |
<?php endif; ?> | |
<?php the_excerpt(); ?> | |
</div> | |
<?php $i++; ?> | |
<?php endforeach; ?> | |
<?php endif; ?> | |
</div> | |
<?php /* This is where it gets ugly. This section checks for all subcategories under the parent issue category. */ | |
$subcategories = get_terms( 'category', 'parent='.$category ); | |
$j = 0; | |
echo '<p>Parent category id: ' . $category . '<br>'; | |
echo 'Number of subcategories found: ' . count($subcategories) . '</p>'; | |
foreach($subcategories as $subcategory) : | |
$j++; | |
$subcategoryId = $subcategory->term_id; | |
$subcategoryName = $subcategory->name; | |
$featured = get_category_by_slug('featured'); | |
$featuredId = $featured->term_id; | |
$featuredPosts = get_posts(array('category__and' => array($subcategoryId, $featuredId))); | |
if ( is_user_logged_in() ) { | |
$lastArgs = array('category' => $subcategoryId, 'category__not_in' => $featuredId, 'post_status' => 'publish,private,draft,inherit' ); | |
} else { | |
$lastArgs = array('category' => $subcategoryId, 'category__not_in' => $featuredId); | |
} | |
$lastposts = get_posts($lastArgs); | |
/* Every other subcategory uses a layout displaying articles on the right. */ ?> | |
<div class="front-page-section"> | |
<?php if( $j % 2 != 0): ?> | |
<div class="five columns alpha"> | |
<h3><?php echo $subcategoryName; ?></h3> | |
<?php | |
/* We get all the posts in this subcategory unless they are in the "featured" category. */ | |
foreach($lastposts as $post) : setup_postdata($post); ?> | |
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br> | |
<?php if(function_exists('coauthors')): ?> | |
<?php coauthors(',<br>'); ?> | |
<?php else: ?> | |
<?php echo the_author_meta('first_name'); ?> <?php echo the_author_meta('last_name'); ?> | |
<?php endif; ?> | |
</p> | |
<?php endforeach; ?> | |
</div> | |
<div class="toc-previews six columns offset-by-one omega"> | |
<?php | |
/* There should only be one featured post in this subcategory, and this is where we display it. */ | |
if($featuredPosts): | |
echo $featuredPosts[0]->post_content; | |
else: | |
echo '<p>Featured content post needs to be created for this category.</p>'; | |
endif; ?> | |
</div> | |
<?php else: ?> | |
<div class="toc-previews six columns alpha"> | |
<?php | |
if($featuredPosts): | |
echo $featuredPosts[0]->post_content; | |
else: | |
echo '<p>Featured content post needs to be created for this category.</p>'; | |
endif; ?> | |
</div> | |
<div class="five columns offset-by-one omega"> | |
<h3><?php echo $subcategoryName; ?></h3> | |
<?php | |
foreach($lastposts as $post) : setup_postdata($post); ?> | |
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br> | |
<?php if(function_exists('coauthors')): ?> | |
<?php coauthors(',<br>'); ?> | |
<?php else: ?> | |
<?php echo the_author_meta('first_name'); ?> <?php echo the_author_meta('last_name'); ?> | |
<?php endif; ?> | |
</p> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> | |
</div> | |
<?php endforeach; ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment