Skip to content

Instantly share code, notes, and snippets.

@Magnacarter
Created May 24, 2015 22:36
Show Gist options
  • Save Magnacarter/b9750c6a2866a638744e to your computer and use it in GitHub Desktop.
Save Magnacarter/b9750c6a2866a638744e to your computer and use it in GitHub Desktop.
Single category page
<?php
/*
* Single Categories
*/
get_header() ?>
<section id="categories">
<div class="gallery-categories grid-100">
<ul>
<?php wp_list_categories( 'title_li=' ) ?>
</ul>
</div>
<div class="single-category-projects">
<?php $category = get_category(get_query_var('cat') );
$args = array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $category,
),
),
);
$projects = new WP_Query( $args ) ?>
<?php if ( $projects->have_posts() ) : ?>
<?php while ( $projects->have_posts() ) : $projects->the_post() ?>
<div class="single-work-wrap">
<div class="single-work grid-33 tablet-grid-50 mobile-grid-100">
<img src="<?php the_field( 'project_image' ) ?>" alt="<?php the_field( 'project_description' ) ?>"/></a>
<div class="gallery-hover grid-50">
<a href="<?php echo esc_url( get_permalink() ) ?>">
<h3><i><?php echo esc_html( get_the_title() ) ?></i></h3>
<h5><i><?php the_field( 'small_title' ) ?></i></h5>
</a>
</div>
</div>
</div>
<?php endwhile; endif;
wp_reset_postdata() ?>
</div>
</section>
<?php get_footer() ?>
@fjarrett
Copy link

I think line 25 should actually be:

'terms' => $category->slug,

Right?

@Magnacarter
Copy link
Author

Yeah, it was working the other way too, but I went ahead and did it your way. Thanks, man!

@fjarrett
Copy link

Coolio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment