Domanda

Ho problemi a avvolgermi la testa nel modo migliore per raggiungere questo obiettivo. Sto cercando di caricare due foto alla volta in un che funge da avvolgimento della presentazione. Attualmente sto ripetendo molto codice e sto semplicemente impostando manualmente un offset ogni volta.

Il mio codice attuale funziona, ma è solo molto goffo. Ecco come appare:

<div id="engagement">
<div>
    <div class="row">
        <?php
            $images = new WP_Query( array(
                'post_parent' => get_the_ID(),
                'post_status' => 'inherit',
                'post_type' => 'attachment',
                'post_mime_type' => 'image',
                'order' => 'ASC',
                'orderby' => 'menu_order ID',
                'offset' => 0,
                'posts_per_page' => 2, // show two images at a time
                'update_post_term_cache' => false,
            ) );    
                foreach ($images->posts as $image) {
                ?>
                <div class="six columns mobile-two">
                    <?php echo wp_get_attachment_image( $image->ID, 'full' ); // get the image ?>
                </div> 
            <?php
            }                               
        ?>                      
    </div>
    <div class="row">
        <?php
            $images = new WP_Query( array(
                'post_parent' => get_the_ID(),
                'post_status' => 'inherit',
                'post_type' => 'attachment',
                'post_mime_type' => 'image',
                'order' => 'ASC',
                'orderby' => 'menu_order ID',
                'offset' => 2,
                'posts_per_page' => 2, // show two images at a time
                'update_post_term_cache' => false,
            ) );    
                foreach ($images->posts as $image) {
                ?>
                <div class="six columns mobile-two">
                    <?php echo wp_get_attachment_image( $image->ID, 'full' ); // get the image ?>
                </div> 
            <?php
            }                               
        ?>                      
    </div>
    <div class="row">
        <?php
            $images = new WP_Query( array(
                'post_parent' => get_the_ID(),
                'post_status' => 'inherit',
                'post_type' => 'attachment',
                'post_mime_type' => 'image',
                'order' => 'ASC',
                'orderby' => 'menu_order ID',
                'offset' => 4,
                'posts_per_page' => 2, // show two images at a time
                'update_post_term_cache' => false,
            ) );    
                foreach ($images->posts as $image) {
                ?>
                <div class="six columns mobile-two">
                    <?php echo wp_get_attachment_image( $image->ID, 'full' ); // get the image ?>
                </div> 
            <?php
            }                               
        ?>                      
    </div>
</div>

Sembra che ci debba essere un modo migliore per farlo.

Grazie!

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top