I'm trying to display a custom post type archive page which displays all the articles of a a custom post type in columns. The columns organize them in their assigned category.
On the main page, I do this successfully with regular posts. I loop thru each category, generate a column, and then loop thru each post within than category to populate the column:
get_header(); ?>
<div id="content">
<div class="categories">
<?php
$cats = get_categories();
foreach ( $cats as $cat ) {
$cat_id = $cat->term_id; ?>
<div class="column" id="c0">
<h2><?php echo $cat->name; ?></h2>
<?php query_posts( "cat=$cat_id&posts_per_page=100" );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_title();
}
wp_reset_postdata();
?>
</div> <!-- /column -->
<?php } //post
} ?> <!-- /foreach -->
</div> <!-- /categories -->
</div> <!-- /content -->
But within the custom post type I use this code and it generates and displays all the categories, but only displays 1 post per category.
get_header();
if(have_posts()) { ?>
<div id="content">
<div class="categories">
<?php
$args = array (
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
//'number' => '4'
);
$terms = get_terms( 'bookmark_categories', $args );
foreach ( $terms as $term ) { ?>
<div class="column" id="c0">
<div class="category">
<h2><?php echo $term->slug ?></h2>
<p class="count">
<?php
$items = get_posts( array (
'post_type' => 'bookmarks',
'numberposts' => - 1,
'taxonomy' => 'bookmark_categories',
'term' => $term->name
) );
$count = count( $items );
echo $count;
?>
</p>
</div>
<?php
$post_args = array (
'post_type' => 'bookmarks',
'bookmark_categories' => $term->name
);
$query = new WP_Query( $post_args );
while ( $query->have_posts() ) {
$query->the_post();
$url = get_post_meta($post->ID,'link_url',true); ?>
<div class="link">
<center>
<a href="<?php echo $url; ?>" target="_blank" title="">
<?php the_post_thumbnail();?>
</a>
</center>
</div>
<?php } // while
wp_reset_postdata(); ?>
</div> <!-- /column -->
<?php } ?> <!-- /foreach -->
</div> <!-- /categories -->
</div> <!-- /content -->
<?php } else { // if posts
get_template_part( 'content', 'none' );
}
get_footer();
offset => 1
?$term->slug
in the args rather than$term->name
.