Last active
August 29, 2015 14:07
-
-
Save anaspk/b19a4bb9fdf800d4cb71 to your computer and use it in GitHub Desktop.
Illustrating difference between index.php and taxonomy archive templates in WordPress
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 get_header(); ?> | |
<div class="container"> | |
<?php | |
if (function_exists('yoast_breadcrumb')) { | |
yoast_breadcrumb('<div class="book-breadcrumb"><p><span class="glyphicon glyphicon-home"></span> ', '</p></div>'); | |
} | |
?> | |
<div class="row"> | |
<div class="col-sm-5 col-md-4"> | |
<?php get_sidebar(); ?> | |
</div> | |
<div class="col-sm-7 col-md-8"> | |
<?php | |
$featured_posts = get_posts(array( | |
'post_type' => 'post', | |
'meta_key' => 'featured_post', | |
'meta_compare' => 'EXISTS', | |
)); | |
$featured_posts_count = count($featured_posts); | |
if ($featured_posts_count > 0): | |
$featured_post = $featured_posts[rand(0, $featured_posts_count - 1)]; | |
?> | |
<div class="row "> | |
<div class="col-sm-12"> | |
<div class="feature-article"> | |
<a href="<?php echo get_permalink($featured_post->ID); ?>"> | |
<?php if (has_post_thumbnail($featured_post->ID)): ?> | |
<?php $thumbnailData = wp_get_attachment_image_src(get_post_thumbnail_id($featured_post->ID), 'featured-article-overview-thumb'); ?> | |
<img src="<?php echo $thumbnailData[0]; ?>" class="img-responsive create-tooltip" data-toggle="tooltip" title="<?php echo get_the_post_thumbnail_caption($featured_post->ID); ?>" /> | |
<?php endif; ?> | |
</a> | |
<div class="date-below-img1"> | |
<span class="date pull-left"><?php echo strtoupper(strftime('%b %d, %Y', strtotime($featured_post->post_date))); ?></span><span class="date pull-right"><img src="<?php echo get_template_directory_uri(); ?>/src/images/articles/comments.jpg" class="img-responsive" /><?php echo $featured_post->comment_count; ?></span> | |
<div class="clearfix"></div> | |
</div> | |
<h3><a href="<?php echo get_permalink($featured_post->ID); ?>"><?php echo apply_filters('the_title', $featured_post->post_title); ?></a></h3> | |
<?php echo apply_filters('the_excerpt', $featured_post->post_excerpt); ?> | |
<a href="<?php echo get_permalink($featured_post->ID); ?>" class="btn btn-danger">Read More</a> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php | |
$counter = 0; | |
if (have_posts()): while (have_posts()) : the_post(); | |
$category = wp_get_post_terms(get_the_ID(), 'category'); | |
if (count($category) > 0) { | |
$category_icon = cc_get_icon_for_category($category[0]->slug); | |
$category_color_code = cc_get_color_code_for_category($category[0]->slug); | |
$category = $category[0]->name; | |
} | |
?> | |
<?php if (($counter % 2) == 0): ?> | |
<div class="row"> | |
<?php endif; ?> | |
<div class="col-md-6"> | |
<div class="article"> | |
<?php if (has_post_thumbnail()): ?> | |
<div class="image-wrapper"> | |
<a href="<?php the_permalink(); ?>"> | |
<?php the_post_thumbnail('article-overview-thumb', array('class' => 'media-object img-responsive create-tooltip', 'data-toggle' => 'tooltip', 'title' => get_the_post_thumbnail_caption())); ?> | |
</a> | |
<div class="image-pasting image-pasting<?php echo $category_color_code; ?>"> | |
<img src="<?php echo $category_icon['url']; ?>" class="img-responsive" width="<?php echo $category_icon['width']; ?>" height="<?php echo $category_icon['height']; ?>" alt="<?php echo $category; ?>"> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php $comments_count = get_comments_number(); ?> | |
<span><a href="<?php the_permalink(); ?>" class="date"><?php echo strtoupper(strftime('%b %d, %Y', strtotime($post->post_date))); ?></a> - <a href="<?php the_permalink(); ?>" class="date"><?php echo $comments_count; ?> COMMENT<?php echo (($comments_count == 1) ? '' : 'S'); ?></a></span> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<?php the_excerpt(); ?> | |
</div> | |
</div> | |
<?php if ((($counter - 1) % 2) == 0): ?> | |
</div> | |
<?php endif; ?> | |
<?php ++$counter; ?> | |
<?php | |
endwhile; | |
endif; | |
?> | |
<?php if ((($counter - 1) % 2) == 0) : ?> | |
</div> | |
<?php endif; ?> | |
<?php | |
$current_page = max(1, get_query_var('paged')); | |
$format = 'page/%#%/'; | |
if ($current_page == 1) | |
$format = '/' . $format; | |
$page_links = paginate_links(array( | |
'base' => get_pagenum_link(1) . '%_%', | |
'format' => $format, | |
'current' => $current_page, | |
'total' => $wp_query->max_num_pages, | |
'prev_next' => true, | |
'next_text' => 'Next Page »', | |
'prev_text' => '« Previous Page', | |
'type' => 'array', | |
)); | |
?> | |
<?php if (!is_null($page_links)): ?> | |
<div class="row"> | |
<div class="col-md-12"> | |
<div class="page-no"> | |
<ul class="pagination"> | |
<?php foreach ($page_links as $page_link): ?> | |
<li><?php echo $page_link; ?></li> | |
<?php endforeach; ?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
<div class="grey-bg just-grey"> | |
</div> | |
<?php get_footer(); ?> |
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 get_header(); ?> | |
<div class="container"> | |
<?php | |
if (function_exists('yoast_breadcrumb')) { | |
yoast_breadcrumb('<div class="book-breadcrumb"><p><span class="glyphicon glyphicon-home"></span> ', '</p></div>'); | |
} | |
?> | |
<div class="row"> | |
<div class="col-sm-5 col-md-4"> | |
<?php get_sidebar(); ?> | |
</div> | |
<div class="col-sm-7 col-md-8"> | |
<div class="row "> | |
<div class="col-sm-12"> | |
<div class="card-type"> | |
<h2><?php single_cat_title(); ?></h2> | |
<span class="sprite heading-border"></span> | |
</div> | |
</div> | |
</div> | |
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<div class="card-review"> | |
<div class="row "> | |
<div class="col-sm-12"> | |
<div class="wrapper"> | |
<div class="row "> | |
<div class="related-card-name"> | |
<div class="col-sm-8"> | |
<h2><a href="<?php the_permalink(); ?>" class="eighteen-pt"><?php the_title(); ?></a></h2> | |
<?php | |
$ratingObj = cc_get_aggregate_rating(get_the_ID()); | |
$reviewsCount = $ratingObj->reviewsCount; | |
if ($reviewsCount > 0) | |
$aggregateRating = ($ratingObj->sumOfRatings / $reviewsCount); | |
else | |
$aggregateRating = 0; | |
?> | |
<a href="<?php the_permalink(); ?>"> | |
<?php echo cc_get_rating_stars_html_1($aggregateRating); ?> | |
</a> | |
<a href="<?php the_permalink(); ?>"><span class="ten-pt">(<?php echo $reviewsCount; ?> ratings and reviews)</span></a> | |
</div> | |
<div class="col-sm-4"> | |
<div class="button pull-right"> | |
<a href="#" class="btn btn-primary">Credit Needed</a> | |
<p><?php the_field('credit_needed'); ?></p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="summary"> | |
<div class="col-sm-3"> | |
<?php echo get_field('affiliate_image_link'); ?> | |
<a href="<?php echo get_field('affiliate_url'); ?>" class="btn btn-danger">Apply Now</a> | |
</div> | |
<div class="col-sm-9"> | |
<?php the_content(); ?> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="pricing"> | |
<div class="col-sm-12"> | |
<table style="width:100%"> | |
<tr> | |
<th colspan="2">Intro APR</th> | |
<th>Regular APR</th> | |
<th>Annual Fee</th> | |
<th colspan="2"> Rewards Program</th> | |
</tr> | |
<tr> | |
<td><p>Purchases</p><p><?php the_field('purchase_intro_apr'); ?></p></td> | |
<td><p>Balance Transfer</p><p><?php the_field('balance_transfer_intro_apr'); ?></p></td> | |
<td></td> | |
<td><?php the_field('annual_fee'); ?></td> | |
<td><p><?php the_field('signup_rewards'); ?></p></td> | |
<td><p><?php the_field('continuous_rewards'); ?></p></td> | |
</tr> | |
</table> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-sm-12"> | |
<div class="more-details"> | |
<a href="<?php the_permalink(); ?>">+ Show More Details +</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php | |
endwhile; | |
endif; | |
?> | |
<?php | |
$current_page = max(1, get_query_var('paged')); | |
$format = 'page/%#%/'; | |
if ($current_page == 1) | |
$format = '/' . $format; | |
$page_links = paginate_links(array( | |
'base' => get_pagenum_link(1) . '%_%', | |
'format' => $format, | |
'current' => $current_page, | |
'total' => $wp_query->max_num_pages, | |
'prev_next' => true, | |
'next_text' => 'Next Page »', | |
'prev_text' => '« Previous Page', | |
'type' => 'array', | |
)); | |
?> | |
<?php if (!is_null($page_links)): ?> | |
<div class="row"> | |
<div class="col-sm-12"> | |
<div class="page-no" style="margin-top: 30px;"> | |
<ul class="pagination"> | |
<?php foreach ($page_links as $page_link): ?> | |
<li><?php echo $page_link; ?></li> | |
<?php endforeach; ?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="grey-bg just-grey"> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment