• I have created an archive page for a custom post type called “Courses.” I want to have all the courses show up alphabetically under an h2 tag with the letter the courses begin with. For instance Math would show up under and h2 tag “M.” It needs to be multi column based on how many courses have the particular letter. So if there are 50 courses that start with “B,” it would need several columns so that it is not a long page. Here’s the code I Have.

    <?php
    /**
     * Template Name: Courses
     *
     * Selectable from a dropdown menu on the edit page screen.
     */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content-container">
            <div id="content" class="clearfix">
                <div id="main-content" style="width:100%"<?php if (get_option('sf_sidebar') =='right'): echo "class=\"alignright\""; endif; ?>>
                    <?php get_template_part('breadcrumbs');?> 
    
    <?php
    // the query
    
    $args=array(
      'post_type' => 'courses',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1,
      'orderby' => 'title',
      'order'   => 'ASC',)
    ?>
    
    <?php
    $the_query = new WP_Query( $args ); ?>
    
    <?php if ( $the_query->have_posts() ) : ?>
    
    	<!-- pagination here -->
    
    	<!-- the loop -->
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<p id="courses-listing"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    	<?php endwhile; ?>
    	<!-- end of the loop -->
    
    	<!-- pagination here -->
    
    	<?php wp_reset_postdata(); ?>
    
    <?php else : ?>
    	<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    
    <?php get_footer(); ?>

    Thanks in advance!!!!

Viewing 1 replies (of 1 total)
  • You’re going to have to find a way to associate the letter you want to go in your <h2> tag to each post – either a category, tag, or custom field….personally I would recommend using a custom taxonomy of the type category that is for this custom post type, so that you have a list of categories each of which is a letter, and assign each post to the appropriate category.

    https://ww.wp.xz.cn/plugins/advanced-custom-fields/

    Then you can create a loop to list posts in each category with a category heading

    http://codex.ww.wp.xz.cn/The_Loop

    Be sure that instead of a <p> tag as you’re using now, that you use a list item (li) which you can style to float left, giving it enough width for as many columns as you want (e.g. 30% for 3 columns, 25% for four columns), and have each (ul) (that starts and closes your category listing) be displayed as block.

Viewing 1 replies (of 1 total)

The topic ‘Multi-Column Custom Post Type Archive Page’ is closed to new replies.