Weitere ähnliche Inhalte
Ähnlich wie WordPressの常識をくつがえす超簡単テーマ doshirouto2014 を作ったのでこれでテーマを理解しよう! (20)
Mehr von Takashi Uemura (20)
Kürzlich hochgeladen (11)
WordPressの常識をくつがえす超簡単テーマ doshirouto2014 を作ったのでこれでテーマを理解しよう!
- 60. 繰り返し (while文)
!
<?php
while(
$a
==
1
):
?>
!
この部分が繰り返されます。
!
<?php
endwhile;
?>
繰り返し文は、新着の記事一覧のページなど、何件もの複数記事
を1ページに表示させるときに使います。
以上をふまえて、doshirouto2014のソースコードを見てみます。→
- 62. <?php
get_header();
?>
header.phpを読み込む
doshirouto2014/index.php
<?php
if
(
have_posts()
)
:
?>
<?
while(
have_posts()
)
:
the_post();
?>
メインテンプレート
<article
id="post-‐<?php
the_ID();
?>"
<?php
post_class();
?>>
while文によるループ処理
<header
class="entry-‐header">
<?php
if
(
is_single()
)
:
the_title(
'<h1>',
'</h1>'
);
else
:
the_title('<h1><a
href="'.esc_url(get_permalink()).'">',
'</a></h1>');
endif;
?>
記事のタイトル
<div
class="entry-‐meta">
<?php
if
(
'post'
==
get_post_type()
)
twentyfourteen_posted_on();
?>
</div>
</header><!-‐-‐
.entry-‐header
-‐-‐>
<div
class="entry-‐content">
<?php
the_content(
'続きを読む→'
);
?>
</div><!-‐-‐
.entry-‐content
-‐-‐>
記事本文を表示する
</article><!-‐-‐
#post-‐##
-‐-‐>
<?php
if
(
is_single()
||
is_page()
)
:
if
(
comments_open()
||
get_comments_number()
)
:
comments_template();
}
endif;
?>
<?php
endwhile;
?>
<?php
twentyfourteen_paging_nav();
?>
<?php
endif;
?>
<?php
sidebar.phpを読み込む
get_sidebar();
get_footer();
footer.phpを読み込む
コメント欄を表示する
記事数分のループ
- 63. <html
lang="ja">
<head>
<meta
charset="UTF-‐8">
<meta
name="viewport"
content="width=device-‐width">
doshirouto/header.php
ヘッダテンプレート
<link
rel="stylesheet"
type="text/css"
href="<?php
echo
get_stylesheet_uri();?>"/>
<title>ヘッダのタイトル
doshirouto2014</title>
<?php
wp_head();
?>
</head>
ヘッダのタイトル
<body
<?php
body_class();
?>>
<div
id="page"
class="hfeed
site">
<header
id="masthead"
class="site-‐header"
role="banner">
<div
class="header-‐main">
<h1
class="site-‐title">
style.cssを読み込む
<a
href="<?php
echo
home_url(
'/'
);
?>">タイトル
-‐
doshirouto2014</a>
</h1>
<div
class="search-‐toggle">
サイトタイトル
<a
href="#search-‐container"
class="screen-‐reader-‐text">検索</a>
</div>
<nav
id="primary-‐navigation"
class="site-‐navigation
primary-‐navigation">
<?php
wp_nav_menu(
array(
'menu_class'
=>
'nav-‐menu'
)
);
?>
</nav>
</div>
ナビゲーションメニュー
<div
id="search-‐container"
class="search-‐box-‐wrapper
hide">
<div
class="search-‐box">
<?php
get_search_form();
?>
</div>
</div>
</header><!-‐-‐
#masthead
-‐-‐>
!
<div
id="main"
class="site-‐main">
!
検索ボックス
- 64. doshirouto2014/sidebar.php
サイドバーテンプレート
<div
id="secondary">
<?php
ブログの説明
$description
=
get_bloginfo(
'description',
'display'
);
if
(
!
empty
(
$description
)
)
:
?>
<h2
class="site-‐description"><?php
echo
esc_html(
$description
);
?></h2>
<?php
endif;
?>
!
<?php
if
(
has_nav_menu(
'secondary'
)
)
:
?>
<nav
role="navigation"
class="navigation
site-‐navigation
secondary-‐navigation">
<?php
wp_nav_menu(
array(
'theme_location'
=>
'secondary'
)
);
?>
</nav>
<?php
endif;
?>
!
<?php
if
(
is_active_sidebar(
'sidebar-‐1'
)
)
:
?>
<div
id="primary-‐sidebar"
class="primary-‐sidebar
widget-‐area">
<?php
dynamic_sidebar(
'sidebar-‐1'
);
?>
</div><!-‐-‐
#primary-‐sidebar
-‐-‐>
<?php
endif;
?>
</div><!-‐-‐
#secondary
-‐-‐>
- 65. doshirouto2014/footer.php
フッタテンプレート
!
</div><!-‐-‐
#main
-‐-‐>
<footer
id="colophon"
class="site-‐footer"
role="contentinfo">
<div
class="site-‐info">
doshirouto2014
</div><!-‐-‐
.site-‐info
-‐-‐>
</footer><!-‐-‐
#colophon
-‐-‐>
</div><!-‐-‐
#page
-‐-‐>
!
<?php
wp_footer();
?>
WordPressのフッタ処理
</body>
</html>