MENU

WordPressの新着を読み込む

新着表示

カテゴリーID1の記事を4件読み込む場合

<!-- ////////////////////////////////////////////////// 新着表示 -->
<?php if ( have_posts() ) : query_posts('showposts=4&cat=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<dl>
<dt><?php the_time('Y.m.d'); ?><?php the_category(' '); ?></dt>
<dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd>
</dl>
<?php endwhile; ?>
<?php endif; ?>

<!-- ////////////////////////////////////////////////// 固定ページで新着使う場合 -->
<?php query_posts('cat=1&posts_per_page=4');
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<dl>
<dt><i class="fa fa-caret-right"></i><?php the_time('Y.m.d'); ?></dt>
<dd><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></dd>
</dl>
<?php endwhile;?>
<?php endif;?>
<?php wp_reset_query();?>

<!-- ////////////////////////////////////////////////// 新着表示(アイキャッチ画像) -->
<?php if ( have_posts() ) : query_posts('showposts=4&cat=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="item-new fade">
<?php the_post_thumbnail('thumbnail'); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php endwhile; ?>
<?php endif; ?> 

<!-- ////////////////////////////////////////////////// アイキャッチのサイズ -->
<?php the_post_thumbnail('thumbnail'); ?> //サムネイルのサイズ
<?php the_post_thumbnail('medium'); ?> //中サイズ
<?php the_post_thumbnail('large'); ?> //大サイズ
<?php the_post_thumbnail('full'); ?> //フルサイズ

<!-- ////////////////////////////////////////////////// アイキャッチの画像がない時 -->
<?php if(has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<!-- アイキャッチの画像がある時 -->
<?php else : ?>
<!-- アイキャッチの画像がない時 -->
<img src="<?php get_option('siteurl'); ?>/images/cmn-images/noimage.gif" alt="noimage">
<?php endif; ?>
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

40代webクリエイター
1人が好き、家が好き、副業と投資でお金貯めてます
31歳で貯金200万円、41歳で2000万円、43歳で2400万円達成中

コメント

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

目次