Custom Post Type UIの表示方法を
使って投稿ページを追加し
index.phpに「タイトル」と「内容」と
「カスタマフィールド」を表示したいです。
手元にありました本によると、下記のように
コードが記載されておりました。
arrayを使って5個まで
表示し、データがなければ
現在お知らせはございません。
と表示する
と、なんとなく理解はできたのですが、
特にループとかは無しで、
シンプルなコードで表示
したいのですが、どうコードを
書いていいのかわかりません。
よろしくお願いします。
Custom Post Type
Post Type Slug 「photo」
Plural Label 「写真」
Singular Label 「写真」
php
1 <?php 2 $args = array( 3 'post_type' => 'news', 4 'posts_per_page' => 5, 5 ); 6 $news = new WP_Query( $args ) ; 7 if ($news->have_posts()) : 8 ?> 9 10 <ul class="time_news"> 11 <?php 12 while ( $news->have_posts() ) : 13 $news->the_post(); 14 ?> 15 <li> 16 <span><?php the_time(get_option('date_format')); ?></span> 17 <a href="<?php the_permalink(); ?>" class="time_text"> 18 <?php the_title(); ?> 19 </a> 20 </li> 21 22 <?php endwhile; ?> 23 24 </ul> 25 26<?php else: ?> 27 28<p>現在お知らせはございません。</p> 29 30 <?php 31endif; 32wp_reset_postdata(); 33?> 34
回答1件
あなたの回答
tips
プレビュー