$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - Custom Post Type - Display all, wrap in groups of 3|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - Custom Post Type - Display all, wrap in groups of 3

matteradmin10PV0评论

I've got a custom post type for staff members in a project I'm working on. I want to display all staff members in a slider, with groups of 3 rotating.

I need my listing to end up looking like this, repeating until all posts are wrapped in "slide" in groups of 3. The last instance of the slide can have only 1 or 2 posts in it if needed, that's no issue.

<div class="slide">
    <div class="employee">
        <div class="em-left">
            {post image}
        </div>
        <div class="em-right">
            <h2>{Title}</h2>
            <p><em>{Position}</em></p>
            <p class="performance"><span class="highlight">{Productivity}</span> productivity</p>
        </div>
    </div>
    <div class="employee">
        <div class="em-left">
            {post image}
        <div class="em-right">
            <h2>{title}</h2>
            <p><em>{position}</em></p>
            <p class="performance"><span class="highlight">{productivity}</span> productivity</p>
        </div>
    </div>
    <div class="employee">
        <div class="em-left">
            {post img}
        </div>
        <div class="em-right">
            <h2>{title}</h2>
            <p><em>{position}</em></p>
            <p class="performance"><span class="highlight">{productivity}</span> productivity</p>
        </div>
    </div>
</div>

My existing query, works great, outputs everything I need in the right format except the "slide" wrap.

<?php

               $args=array(
                    'post_type' => 'staff',
                    'post_status' => 'publish',
                    'orderby'   => 'menu_order',
                    'order'     => 'ASC',

                );

                $my_query = null;
                $my_query = new WP_Query($args);

                if( $my_query->have_posts() ) {

                $i = 1;
                while ($my_query->have_posts()) : $my_query->the_post();

                $id = get_the_ID();

                // grab custom fields
                rwmb_meta( $field_id);  

            ?>

            <?php 
                // grab photos
                $images = rwmb_meta( 'staff-photo','size=thumbnail' );
                $i = 1;
                if ( !empty( $images ) ) {
                    foreach ( $images as $image ) {
                        echo "<div class='employee'><div class='em-left'><img src='{$image['url']}' class='img-round'></a></div><div class='em-right'>";
                        if($i == 1) break;
                    }
                } else {
                    echo "<div class='employee'><div class='em-left'><img src='".get_bloginfo('template_url')."/images/placeholder.jpg' class='img-round'></a></div><div class='em-right'>";
                }

            ?>
                    <h2><?php the_title(); ?></h2>
                    <p><em><?php echo rwmb_meta( 'position' ); ?></em></p>
                    <p class="performance"><span class="highlight"><?php echo rwmb_meta( 'productivity' ); ?>%</span> productivity</p>

                </div><!-- em-right -->
            </div><!-- employee -->

            <?php  

                endwhile;
                }
                wp_reset_query();
            ?>
Post a comment

comment list (0)

  1. No comments so far