• hi!

    Im trying to output 9 columns post list from a CPT and respective categories. Not sure why its not working. This is what i got so far:

    <?php
    
    $last_char = '';
    $args=array(
        'post_type' => 'portfolio',
        'orderby' => 'title',
        'order' => 'ASC',
        'posts_per_page'=>-1,
        'portfolio-category' => 'indie',
        'ignore_sticky_posts'=>1
    );
    
    $my_query = new WP_Query($args);
    
    $columnCount = 0;
    
    ?>
    
    <?php if( $my_query->have_posts() ) : ?>
     <?php  echo 'Alphabetic index of all ' . count($my_query->posts) . ' posts'; ?>
    
        <table>
            <tr>
                <?php while ($my_query->have_posts()) : ?>
                    <?php if ($columnCount == 8): ?>
                        </tr>
                        <tr>
                        <?php $columnCount = 0; ?>
                    <?php endif; ?>
    
                    <td>
                    <?php $my_query->the_post(); ?>
                    <?php $this_char = strtoupper(substr($post->post_title,0,1)); ?>
    
                    <?php if ($this_char != $last_char) :
                         $last_char = $this_char; ?>
                        <h2> <?= $last_char; ?></h2>
                    <?php endif; ?>
    
                    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                    </td>
                <?php endwhile; ?>
                <?php if ($columnCount != 8): ?>
                    </tr><!-- Make sure the last row gets closed. -->
                <?php endif; ?>
        </table>
    <?php endif; ?>
    
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Trying to output columns with the loop, not working. Why?’ is closed to new replies.