Support » Themes and Templates » How to set up the archive-$postype page to display in a grid or columns?

  • I’m on a self-hosted site, so no link. I would like to display what the following script outputs in either columns or grid form. I’ve tried many, many things but nothing works, so any help would be appreciated.

    get_header(); ?>
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    						<header class="page-header">
    					<h1 class="page-title">
    						<?php echo $post->post_type; ?>
    		<?php if ( have_posts() ) : ?>
    			<?php /* Start the Loop */ ?>
    			<?php query_posts($query_string . '&orderby=title&order=ASC'); ?>
    				<?php while ( have_posts() ) : the_post(); ?>  
    				<?php get_template_part( 'content-archive' ); ?>
    			<?php  endwhile; ?>
    			<?php twentytwelve_content_nav( 'nav-below' ); ?>
    		<?php else : ?>
    			<article id="post-0" class="post no-results not-found">
    			<?php if ( current_user_can( 'edit_posts' ) ) :
    				// Show a different message to a logged-in user who can add posts.
    				<header class="entry-header">
    					<h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
    				<div class="entry-content">
    					<p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
    				</div><!-- .entry-content -->
    			<?php else :
    				// Show the default message to everyone else.
    				<header class="entry-header">
    					<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
    				<div class="entry-content">
    					<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
    					<?php get_search_form(); ?>
    				</div><!-- .entry-content -->
    			<?php endif; // end current_user_can() check ?>
    			</article><!-- #post-0 -->
    		<?php endif; // end have_posts() check ?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • Michael


    Forum Moderator

    I just trecently posted something on my site to show posts in two columns in a Twenty Twelve child theme

    this should be easily adaptable to be used in an archive-$postype template, by changing the conditional at the start of the code, and to be adapted to more than two columns by changing the modulus operator.

    how many columns do you need?
    what is your post_type or are there severals?

    Hi and thanks. I’ve been enjoying reading your posts on grids, but I’m too much of a newbie to implement them easily. The post_type is called “producers”, but whatever I do in this page I want to adapt to taxonomy page which has a similar structure.

    So, reading your post, do I do the following?
    1. change the is_category() to is post_type () [ or would it be is post_type (‘producers’)?

    2. change this line? Here I may need some direction to insert a third column.
    if( $wp_query->current_post%2 == 0 ) $classes[] = ‘two-column-post-left’;

    btw, I assume that all of the code in the post you wrote should be surrounded by
    <?php ‘the code’ ?>
    Is that right?

    Ok: I think we’re close.
    I’ve got it to work on the custom post type index page by using is_post_type_archive and custom taxonomy using is_tax. This is very exciting.

    But, the three column code is over my head



    Forum Moderator

    some direction to insert a third column


    if( $wp_query->current_post%3 == 0 ) $classes[] = 'column-post-left';

    together with:

    .column-post-left { clear: left; margin-left:0; }

    It’s not formatting the custom taxonomies


    these changes to the functions.php file are keeping the admin panel from reloading after resetting the settings

    these changes in particular or general any changes in functions.php?

    to get some error messages, possibly enable DEBUG in wp-config.php:

    Ok; excellent. Thank you, thank you, thank you.

    One (hopefully last) question on this topic: how do I make the css formatting only apply to is_tax and is_post_type_archive ? I don’t want the pages on the rest of the site to have this formatting?

    btw, functions.php is fine.



    Forum Moderator

    how do I make the css formatting only apply to is_tax and is_post_type_archive ?

    due to the conditional checks inthe code, the css classes should only be added to your intended (web) pages;

    if they appear elsewhere, try to use the body_class output to make the styles more specific:
    I am not sure what these would be for a taxonoy archive or post_type archive – but you can check either by viewing the html ouput of these page in the browser and looking for the css classes in the body tag, or using a browser inspection tool

    then, you could possibly use for example (replace the real taxonomy name and post_type):
    .tax-[taxonomy name] .column-post-left { ... }
    .single-[post_type] .column-post-left { ... }

    Yes, it’s strange that the columns are reformatting all the content on the blog and not just what’s in the conditional statement below:

    function category_two_column_classes( $classes ) {
    global $wp_query;
    if( is_post_type_archive() || is_tax ) :
    $classes[] = 'two-column-post';
    if( $wp_query->current_post%2 == 0 ) $classes[] = 'two-column-post-left';
    return $classes;

    I see my error: is_tax should be is_tax()

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to set up the archive-$postype page to display in a grid or columns?’ is closed to new replies.