さまざまな列のスタイルのカスタム投稿
質問
COL-8(サムネイル)およびCOL-4(コンテンツ)でスティッキー/機能の作業を使用してカスタムタイプの投稿を出力しようとしている場合は、POSTの残りがCOL-4に入る必要があります。これまでのようなコードを試してみましたが、すべての投稿を出力してください。
<?php
$loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '1') );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-8 columns">
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
</div>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h2>
<?php echo the_content(); ?>
</div>
<?php endwhile; ?>
<div class="clear"></div>
<div class="row">
<?php
$loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '3') );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h4>
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
<?php echo the_content(); ?>
</div>
<?php endwhile; ?>
</div>
.
私がしようとしていることを説明するために以下の画像を見てください。
解決
wp_query e.gのoffset Paramer。
<?php
$loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '1') );
$counter=0;
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); $counter++; ?>
<div class="col-8 columns">
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
</div>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h2>
<?php echo the_content(); ?>
</div>
<?php endwhile; ?>
<div class="clear"></div>
<div class="row">
<?php
$loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '3', 'offset' => '1' ) );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h4>
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
<?php echo the_content(); ?>
</div>
<?php endwhile; ?>
</div>
.
基本的には、クエリ内の最初のXX投稿を無視して、クエリの最初の投稿を無視したい場合は、offset=> 1を使用することができます
私はそれが「Rand」注文とうまくいくとは思わない、ランドは必需品ですか?
編集:カウント&1クエリの使用
.
<?php
$loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '4') );
$count = 1;
while ( $loop->have_posts() ) : $loop->the_post();
if($count == '1') { ?>
<div class="col-8 columns">
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
</div>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h4>
<?php echo the_content(); ?>
</div>
<?php } else { ?>
<div class="col-4 columns">
<h4 class="project_title"><?php the_title(); ?></h4>
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php echo get_the_post_thumbnail(); ?>
<?php endif; ?>
<?php echo the_content(); ?>
</div>
<?php
}
$count++;
endwhile;
wp_reset_postdata();
?>
テストされていませんが、基本的には投稿を数えてカウント番号に応じてHTMLコードを変更します。