HTML → WordPress 化(基本パターン)
静的なHTMLの構造をWordPressテンプレート階層(header.php, footer.php, sidebar.php, index.php, single.php, page.php)に置き換え
テンプレートタグとループを利用して動的にする
メモ
- header.php:doctype 〜 body を配置。wp_head() を忘れずに。
- footer.php:閉じタグ前に wp_footer() を配置。
- index.php:メインループで投稿一覧を表示(the_title(), the_excerpt() 等)。
- single.php:単一投稿表示(the_content(), comments_template())。
- functions.php:サイドバー登録やメニュー登録、ウィジェットエリアもろもろの定義。
- wp_head / wp_footer の配置はプラグインやスクリプト挙動に影響するため必須。
- テンプレートパーツは get_template_part(‘template-parts/content’, get_post_type()) のように分割すると保守しやすいかもしれない。そういうサイト見る限り多い
PHP
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php get_template_part('template-parts/header','site'); ?>
チェックリスト
- wp_head / wp_footer を設置
- ループは have_posts / the_post を使って
- テンプレートパーツを分離
次single.php と archive.php のスタイルを作り
投稿の詳細表示とアーカイブでの見た目を整える

コメント