JiveDig
11/25/2013 - 6:29 PM

new wp_query to show a list of custom post type (cpt) post titles

new wp_query to show a list of custom post type (cpt) post titles

	<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'prefix_do_resident_query' );
function prefix_do_resident_query() {

    // Show Posts
    $args = array(
        'post_type'      => 'resident',
        'posts_per_page' => '36',
        'post_status'    => 'publish',
    );
    
    $post_type = new WP_Query( $args );

    genesis_do_post_title();

    if ( $post_type->have_posts() ) {

        $i = 0;

        while ( $post_type->have_posts() ) : $post_type->the_post();
        ?>
            <div class="one-fourth<?php if ($i++ % 4 == 0) echo ' first'; ?> resident">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php
                    if ( has_post_thumbnail() ) {
                        the_post_thumbnail('resident');
                    } else {
                        echo '<img src="' . get_stylesheet_directory_uri() . '/images/no-image.png" alt="No Resident Image">';
                    }
                    echo '<div class="detail res-name">' . get_the_title() . '</div>';
                    ?>
                </a>
                ?>
            </div>
        <?php
        endwhile;
        do_action( 'genesis_after_endwhile' ); // Adds pagination (DOESN'T WORK?)

    } // if
    wp_reset_postdata();

}