Created
February 8, 2015 11:07
-
-
Save johanbrook/4312041a2e3b2cf7b784 to your computer and use it in GitHub Desktop.
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 | |
$categories = get_terms("worktype", array( | |
"orderby" => "count", | |
"order" => "DESC" | |
)); | |
function get_next_post_with_thumbnail($posts, $index) { | |
if($index == count($posts)) { | |
return null; | |
} | |
return (!has_post_thumbnail($posts[$index]->ID)) | |
? get_next_post_with_thumbnail($posts, ++$index) : get_the_post_thumbnail($posts[$index]->ID, "thumbnail"); | |
} | |
?> | |
<?php get_header();?> | |
<h1 class="page-title">Portfolio</h1> | |
<ul class="grid-list"> | |
<?php if($categories) : foreach($categories as $type) : ?> | |
<li> | |
<?php | |
$first_posts = get_posts("worktype=".$type->slug."&post_type=portfolio"); | |
$image = get_next_post_with_thumbnail($first_posts, 0); | |
?> | |
<a href="<?php echo get_term_link($type);?>"> | |
<?php if($image != null) echo $image;?> | |
<h2> | |
<?php echo $type->name;?> | |
<span title="Antal arbeten i <?php echo $type->name;?>" class="bubble"><?php echo $type->count;?></span> | |
</h2> | |
</a> | |
</li> | |
<?php endforeach; endif;?> | |
</ul> | |
<?php get_footer();?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment