現在、クライアントのカスタム テーマを作成していますが、これについては専門家ではありません。私の質問は、同じカテゴリの投稿に異なるスタイルを作成する方法です。現在私のテーマで
最初の投稿の新しいクエリを開始する
<?php query_posts('showposts=1&cat=videos&offset=0'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="first-news">
<h2><a href="<?php the_permalink() ?><?php the_title(); ?></a></h2>
<?php if( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('video-thumb');?</a><?php} ?>
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?>
次に、別の div とスタイルを使用して、残りの 4 つの投稿に対して同じクエリを再度開始します
<?php query_posts('showposts=4&cat=videos&offset=1'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="second-news">
<h3><a href="<?php the_permalink() ?><?php the_title(); ?></a></h3>
<?php if( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('news-thumb'); ?></a><?php } ?>
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?>
これは完全に機能しています。これは正しいですか? 投稿を一度だけクエリし、同じカテゴリから異なるスタイルの必要な数の投稿を取得する良い解決策があると思います。私が欲しいのは下の画像です。