1 2 3 4 5 6 7 8 9 10 |
/* Theme Name: テーマの名前(必須) Theme URL: テーマのサイトのURI Description: テーマの説明 Author: 作者の名前 Version: テーマのバージョン Tags: テーマの特徴を表すタグ(カンマ区切り/オプション) License: テーマのライセンス License URI: テーマのライセンスのURI */ |
WordPress 任意のテンプレートパーツを読み込む
//content.php を呼び出す
1 |
<?php get_template_part( 'content' ); ?> |
// […]
個別記事ページ
コード例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php get_header(); ?> <main> <?php if(have_posts()): while(have_posts()):the_post(); ?> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('Y.m.d'); ?></time> <p><?php the_category(', '); ?></p> <p><?php the_content('Read more'); ?></p> <?php endwhile; endif; ?> <?php previous_post_link('%link','古い記事へ'); ?> <?php next_post_link('%link','新しい記事へ'); ?> </main> <?php get_sidebar(); ?> <?php get_footer(); ?> |
固定ページ
サンプルコード
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php get_header(); ?> <?php get_header(); ?> <main> <p><?php single_cat_title(); ?>カテゴリー記事の一覧です</p> <?php while ( have_posts() ) : the_post(); ?> //テンプレートがあれば <?php get_template_part( 'content', 'page' ); ?> //テンプレートがなければ <?php the_content(); ?> <?php endwhile; // end of the loop. ?> </main> <?php get_sidebar(); ?> <?php get_footer(); ?> |
カテゴリーページ
サンプルコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php get_header(); ?> <main> <p><?php single_cat_title(); ?>カテゴリー記事の一覧です</p> <?php if(have_posts()): while(have_posts()):the_post(); ?> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('Y.m.d'); ?></time> <p><?php the_category(', '); ?></p> <p><?php the_content('Read more'); ?></p> <?php endwhile; endif; ?> <?php previous_posts_link('新しい投稿ページへ'); ?> <?php next_posts_link('古い投稿ページへ'); ?> </main> <?php get_sidebar(); ?> <?php get_footer(); ?> |
特定のカテゴリー投稿の一覧表示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php $arg = array( 'posts_per_page' => 10, // 表示する件数 'orderby' => 'date', // 日付ソート 'order' => 'DESC', // DESCで降順、ASCで昇順 'category_name' => 'wp-customize' // カテゴリーのスラッグを指定 ); $posts = get_posts( $arg ); if( $posts ): ?> <ul> <?php foreach ( $posts as $post ) : setup_postdata( $post ); ?> <li><?php the_time( 'Y.m.d' ); ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> <?php endif; wp_reset_postdata(); ?> |
カスタム投稿名を出力
カスタム投稿名を出力するコード
1 |
<?php echo esc_html(get_post_type_object(get_post_type())->label); ?> |