###前提・実現したいこと
- TOPページが最新記事一覧のページがあります。
- このページの最上部に特定記事1つを指定して表示させたい
- 表示方法(スタイル)は記事一覧のスタイルと一緒にしたい
###該当のソースコード
■ home.php(TOPページ)の内容
<?php get_header(); ?> <div id="content" class="clearfix"> <div id="contentInner"> <div class="st-main"> ---> ここに記事1件、投稿ID指定で表示させたい <?php get_template_part( 'itiran' ); ?> <?php get_template_part( 'st-pagenavi' ); //ページナビ読み込み ?> </div> <?php get_template_part( 'sns-top' ); //ソーシャルボタン読み込み ?> </div> </div> <!-- /#contentInner --> <?php get_sidebar(); ?> </div> <!-- /#content --> <?php get_footer(); ?>
■リストitiran.phpの内容
<?php /** * トップやアーカイブ一覧 */ ?> <div class="kanren"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <dl class="clearfix"> <dt><a href="<?php the_permalink(); ?>"> <?php if ( has_post_thumbnail() ): // サムネイルを持っているときの処理 ?> <?php the_post_thumbnail( 'thumbnail' ); ?> <?php else: // サムネイルを持っていないときの処理 ?> <img src="<?php echo get_template_directory_uri(); ?>/images/no-img.png" alt="no image" title="no image" width="100" height="100" /> <?php endif; ?> </a></dt> <dd> <p class="kanren-t"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></p> <div class="blog_info"> <p><i class="fa fa-clock-o"></i> <?php the_time( 'Y/m/d' ); ?> <span class="pcone"> <i class="fa fa-folder-open-o" aria-hidden="true"></i>-<?php the_category( ', ' ) ?><br/> <?php the_tags( '<i class="fa fa-tags"></i> ', ', ' ); ?> </span></p> </div> <div class="smanone2"> <?php the_excerpt(); //抜粋文 ?> </div> </dd> </dl> <?php endwhile; else: ?> <p>記事がありません</p> <?php endif; ?> </div>
###試したこと
<?php get_template_part( 'itiran' ); ?>に記事IDを渡して特定記事の内容を1件分だけ取得することができないか?と思い、調べているのですが方法がわかります。他の方法でもよいのですが、できるだけ簡単に実装できる方法がよいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/30 05:38
退会済みユーザー
2017/09/30 05:54 編集
2017/09/30 05:53