【WordPress ソースコード】入門編:フォトサイト
テーマディレクトリ構成
~/wp-content/themes/photo
├─img
│ ├─favicon.ico
│ ├─logo.svg
│ ├─detail.jpg
│ └─mainvisual.jpg
│
├─header.php
├─index.php
├─footer.php
├─functions.php
└─style.css
別タブで開く
header.php
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo bloginfo('name'); ?></title>
<meta name="description" content="<?php bloginfo('description'); ?>">
<link rel="icon" href="<?php echo esc_url(get_theme_file_uri('img/favicon.ico')); ?>">
<?php wp_head(); ?>
</head>
<body>
<div class="container">
<header id="header">
<h1 class="site-title">
<a href="<?php echo esc_url(home_url()); ?>"><img src="<?php echo esc_url(get_theme_file_uri('img/logo.svg')); ?>" alt="PHOTO BOOK"></a>
</h1>
</header>
index.php
別タブで開く
index.php
<?php get_header(); ?>
<main>
<div id="mainvisual">
<img src="<?php echo esc_url(get_theme_file_uri('img/mainvisual.jpg')); ?>" alt="テキストテキストテキスト">
</div>
<section id="index">
<div class="inner">
<h2 class="section-title">INDEX</h2>
<?php
// スラッグから固定ページの本文を取得
$page_data = get_page_by_path('index');
$page = get_post($page_data);
echo $page->post_content;
?>
</div>
</section>
<section id="detail">
<div class="inner">
<h2 class="section-title">DETAIL</h2>
<div class="content">
<img class="img" src="<?php echo esc_url(get_theme_file_uri('img/detail.jpg')); ?>" alt="">
<div class="text">
<p class="title">タイトルタイトルタイトル</p>
<dl>
<dt>著者</dt>
<dd>タイトルタイトルタイトル</dd>
<dt>出版社</dt>
<dd>タイトルタイトルタイトル</dd>
<dt>発行年</dt>
<dd>タイトルタイトルタイトル</dd>
</dl>
<p>
テキストテキストテキストテキストテキストテキスト
テキストテキストテキストテキストテキストテキスト
</p>
<a class="link" href="#" target="_blank" rel="noopener noreferrer">オンラインストアで見る</a>
</div>
</div>
</div>
</section>
</main>
<?php get_footer(); ?>
別タブで開く
footer.php
<footer id="footer">
<p class="inner">© <?php echo bloginfo('name'); ?></p>
</footer>
</div>
<?php wp_footer(); ?>
</body>
</html>
functions.php
別タブで開く
functions.php
<?php
/**************************************************
CSSファイルの読み込み
**************************************************/
function my_enqueue_styles() {
wp_enqueue_style('ress', '//unpkg.com/ress/dist/ress.min.css', array(), false, 'all');
wp_enqueue_style('style', get_stylesheet_uri(), array('ress'), false, 'all');
}
add_action('wp_enqueue_scripts', 'my_enqueue_styles');
style.css
別タブで開く
style.css
@charset "UTF-8";
/*
Theme Name: photo
*/
html {
font-size: 100%;
}
body {
background-color: #f4f9ff;
color: #333;
font-size: 0.875rem;
}
img {
max-width: 100%;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
.inner {
max-width: 600px;
margin: 0 auto;
}
.section-title {
font-size: 1.125rem;
font-weight: bold;
margin-bottom: 10px;
}
/*-------------------------------------------
ヘッダー
-------------------------------------------*/
#header {
margin-top: 60px;
}
#header .site-title {
width: 160px;
line-height: 1px;
margin-bottom: 15px;
}
#header .site-title a {
display: block;
}
/*-------------------------------------------
Mainvisual
-------------------------------------------*/
#mainvisual {
margin-bottom: 60px;
}
/*-------------------------------------------
Index
-------------------------------------------*/
#index {
background-color: #fff;
padding: 30px 0;
margin-bottom: 60px;
}
#index ol {
margin-left: 20px;
}
#index li {
margin-bottom: 20px;
}
#index li:last-child {
margin-bottom: 0;
}
/*-------------------------------------------
Detail
-------------------------------------------*/
#detail {
margin-bottom: 100px;
}
#detail .content {
display: flex;
align-items: flex-start;
}
#detail .content .title {
font-size: 1.125rem;
font-weight: bold;
}
#detail .content .img {
width: 270px;
margin-right: 60px;
}
#detail .content .text p {
margin-bottom: 20px;
}
#detail .content dl {
display: flex;
flex-wrap: wrap;
padding: 16px 0;
margin-bottom: 25px;
border-top: solid 1px #dedede;
border-bottom: solid 1px #dedede;
}
#detail .content dt {
width: 25%;
}
#detail .content dd {
width: 75%;
}
#detail .content .link {
color: #333;
}
#detail .content .link:hover {
opacity: 0.8;
}
/*-------------------------------------------
footer
-------------------------------------------*/
#footer {
font-size: 0.625rem;
padding: 15px 0;
}
/*-------------------------------------------
SP
-------------------------------------------*/
@media screen and (max-width: 1024px) {
.inner {
padding: 0 40px;
}
/*-------------------------------------------
ヘッダー
-------------------------------------------*/
#header {
padding: 0 10px;
}
/*-------------------------------------------
Mainvisual
-------------------------------------------*/
#mainvisual {
padding: 0 10px;
}
/*-------------------------------------------
Detail
-------------------------------------------*/
#detail .content {
flex-direction: column;
}
#detail .content .img {
width: 100%;
margin: 0 0 25px 0;
}
}