0

結合したときに常に幅 900px の画像の行が必要です。

1 つの画像の高さが可変で、幅が 900px の場合、2 つの画像の 1 つは幅 300px で、もう 1 つは幅 600px です。

これが私のこれまでの試みです。

    <?php
        $maxHeight = 400;//maximum height of a thumb
        $offset = 0;//start on recent post
        $maxRowWidth = 900;//maximum width of a row
        $stopId=20;//max of 20 posts 
        set_post_thumbnail_size( 9999, $maxHeight );
        $rowWidth=0;//initial row width
        $column = 0;    

        if ( have_posts() ) : while ( have_posts() ) : the_post();
            if ( has_post_thumbnail() ) {
                $tn_id = get_post_thumbnail_id( $post->ID );
                $img = wp_get_attachment_image_src( $tn_id, array(9999,$maxHeight) );
                $width = $img[1];//holds the default image width given max height
                $height = $img[2];//not used yet
                $column = $column+1;
                $rowWidth = $rowWidth+$width;
                if ($rowWidth > $maxRowWidth){
                    $aspectRatio = $rowWidth / $maxHeight;
                    $height= $maxRowWidth / $aspectRatio;
                    //I get an error here when I nest this loop wordpress doesn't like this
                    $query = 'showposts='.$column.'&offset='.$offset;

                    query_posts('$query');
                    if ( have_posts() ) : while ( have_posts() ) : the_post(); 
                        if ( has_post_thumbnail() ) {
                            $img = wp_get_attachment_image_src( $tn_id, array(9999,$height) );
                            the_post_thumbnail();
                                                    }
                        endwhile; else:
                    endif;
                    //wp_reset_postdata();  //commented out because I don't know if I need it
                    $offset = $offset+1;
                    $column = 0;
                    $rowWidth = 0;
                }
            }
        endwhile; else:
    ?>
4

0 に答える 0