前回まで

functions.phpでスタイルシートを読み込む
1 2 3 4 5 |
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'my_style', get_stylesheet_directory_uri() . '/style.css' );//スタイルシート wp_enqueue_script( 'my_script', get_stylesheet_directory_uri() . '/assets/js/script.js' );//スクリプト } |
投稿ページでサムネイルを追加する
- function.phpにadd_theme_support(‘post-thumbnails’);を追記
- 新規投稿追加
- 右上の表示オプションのボックス内を確認
- アイキャッチ画像にチェックを入れる
- 投稿ページにアイキャッチ画像の選択が追加される
コメント機能を作る
<?php comments_template();?>を挿入
カテゴリを一つだけ取得
<?php $cat_info = get_category( $cat );echo esc_html( $cat_info->name ); ?>を挿入
記事一覧ページでページ遷移する(ページめくり)
- WP-PageNavi(プラグイン)を導入
- <?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>を任意の場所に挿入
用例 (index.phpの部分)
記事一覧テンプレート
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php if(have_posts()): while(have_posts()):the_post();?> <a href="<?php the_permalink();//記事リンク ?>"><?php the_title();//記事タイトル ?></a> <?php the_excerpt();//記事抜粋?> <?php the_time( 'Y.m.d' );//記事日付 ?> <?php endwhile;else:?> <?php if(is_search()):?> <p>検索結果はありませんでした。</p> <?php else:?> <p>記事はありませんでした。</p> <?php endif;?> <?php endif;?> |
投稿ページテンプレート
1 2 3 4 5 6 7 8 9 10 |
<?php if(have_posts()): while(have_posts()): the_post();?> <h1><?php the_title(); ?></h1> <?php the_post_thumbnail( 'full' );//サムネイル画像 ?> <?php the_time( 'Y.m.d' ); ?> <?php the_content();//投稿本文 ?> <?php the_category(' ');//カテゴリ ?> <?php next_post_link('%link', '<< 次の記事');//ページ遷移 ?> <?php previous_post_link('%link', '前の記事 >>'); //ページ遷移?> <?php comments_template();//コメント ?> <?php endwhile; endif; ?> |
自作ワードプレステーマの最低限を作るシリーズ一覧







コメントを残す