Wordpressで自分好みのテーマを作る

74
自分だけの WordPress テーマを作る 2011/1/8 フリーランスシステムエンジニア 上村 崇 @uemera

description

 

Transcript of Wordpressで自分好みのテーマを作る

Page 1: Wordpressで自分好みのテーマを作る

自分だけのWordPressテーマを作る

2011/1/8フリーランスシステムエンジニア上村 崇 @uemera

Page 2: Wordpressで自分好みのテーマを作る

軽く自己紹介

Page 3: Wordpressで自分好みのテーマを作る

しがないフリーランスSE

軽く自己紹介

Page 4: Wordpressで自分好みのテーマを作る

軽く自己紹介

しがないフリーランスSE組込みエンジニア(カーナビ)

Page 5: Wordpressで自分好みのテーマを作る

軽く自己紹介

しがないフリーランスSE組込みエンジニア(カーナビ)副業で少しWeb

Page 6: Wordpressで自分好みのテーマを作る

このプレゼンは

Page 7: Wordpressで自分好みのテーマを作る

・去年、別の場所で発表しました。

Page 8: Wordpressで自分好みのテーマを作る

・去年、別の場所で発表しました。

・30分ほどのボリュームがあります。

Page 9: Wordpressで自分好みのテーマを作る

・去年、別の場所で発表しました。

・30分ほどのボリュームがあります。

・昼にビビンパを食べて舌をヤケドしま した。

Page 10: Wordpressで自分好みのテーマを作る

それでは本題

Page 11: Wordpressで自分好みのテーマを作る

WordPressとは

Page 12: Wordpressで自分好みのテーマを作る

ブログツールの一つ

Page 13: Wordpressで自分好みのテーマを作る

PHPで作られています

Page 14: Wordpressで自分好みのテーマを作る

MySQLを使っています

Page 15: Wordpressで自分好みのテーマを作る

日本

全世界

ブログツール比較

Page 16: Wordpressで自分好みのテーマを作る

日本

全世界

CMS比較

Page 17: Wordpressで自分好みのテーマを作る

テーマってどんなの?

Page 18: Wordpressで自分好みのテーマを作る

テーマは無数にあります

Page 19: Wordpressで自分好みのテーマを作る
Page 20: Wordpressで自分好みのテーマを作る
Page 21: Wordpressで自分好みのテーマを作る
Page 22: Wordpressで自分好みのテーマを作る
Page 23: Wordpressで自分好みのテーマを作る
Page 24: Wordpressで自分好みのテーマを作る
Page 25: Wordpressで自分好みのテーマを作る
Page 26: Wordpressで自分好みのテーマを作る
Page 27: Wordpressで自分好みのテーマを作る

自分好みのテーマを作れれば素敵ですね!

Page 28: Wordpressで自分好みのテーマを作る

もちろんHTMLスタイルシートの知識は必要ですが

Page 29: Wordpressで自分好みのテーマを作る

必要な知識は3つ

Page 30: Wordpressで自分好みのテーマを作る

WordPressディレクトリ構成 PHP テンプレート

テンプレートタグ

Page 31: Wordpressで自分好みのテーマを作る

WordPressディレクトリ構成1

Page 32: Wordpressで自分好みのテーマを作る

themes

テーマは2つ ※WordPress 2.x での話

Page 33: Wordpressで自分好みのテーマを作る

WordPress3.xはテーマ1つ

Page 34: Wordpressで自分好みのテーマを作る

PHPの基本

2

Page 35: Wordpressで自分好みのテーマを作る

まず、普通のHTMLファイルはこんなのです。

Page 36: Wordpressで自分好みのテーマを作る

<html> <head> <title>文書のタイトル</title> </head> <body> 文書の本文 </body> </html>

index.html

Page 37: Wordpressで自分好みのテーマを作る

同じことをPHPでやると、こうなります。

Page 38: Wordpressで自分好みのテーマを作る

<?phpecho "<html>";echo " <head>";echo " <title>文書のタイトル</title>";echo " </head>";echo " <body>";echo " 文書の本文";echo " </body>";echo "</html>";?>

index.php

Page 39: Wordpressで自分好みのテーマを作る

別の方法もあります。

Page 40: Wordpressで自分好みのテーマを作る

<?php $title = "文書のタイトル"; $contents = "文書の本文";?><html> <head> <title><?php echo $title ?></title> </head> <body> <?php echo $contents ?> </body> </html>

index.php

Page 41: Wordpressで自分好みのテーマを作る

つまり、PHPを書くときは<?php ?> で囲む

Page 42: Wordpressで自分好みのテーマを作る

テンプレートとテンプレートタグ

3

Page 43: Wordpressで自分好みのテーマを作る

ブロックに分けて考えてみます

Page 44: Wordpressで自分好みのテーマを作る

sidebar

footer

maincontents

header

Page 45: Wordpressで自分好みのテーマを作る

コードで表すとこうなります→

Page 46: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

Page 47: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

WordPressループ(Main Contents)※WordPress3ではloop.php内にあり

Page 48: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

sidebar

footer

maincontents

header

Page 49: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

sidebar

footer

maincontents

header

Page 50: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

footer

maincontents

header

Sidebar

Page 51: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

sidebar

maincontents

header

footer

Page 52: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php

テンプレートタグWordPress組込の関数

Page 53: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.phpheader.php

sidebar.phpfooter.php

Page 54: Wordpressで自分好みのテーマを作る

default

テンプレート

Page 55: Wordpressで自分好みのテーマを作る

Headerについて詳しく見てみます。

Page 56: Wordpressで自分好みのテーマを作る

header

Page 57: Wordpressで自分好みのテーマを作る

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head><meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title> <?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?>

</title><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css” /><style type="text/css”> #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-ltr.jpg“) }</style><?php wp_head(); ?>

</head><body><div id="page"><div id="header" role="banner"><div id="headerimg"> <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1> <div class="description"><?php bloginfo('description'); ?></div></div></div>

header.php

Page 58: Wordpressで自分好みのテーマを作る

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head><meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title> <?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?>

</title><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css” /><style type="text/css”> #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-ltr.jpg“) }</style><?php wp_head(); ?>

</head><body><div id="page"><div id="header" role="banner"><div id="headerimg"> <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1> <div class="description"><?php bloginfo('description'); ?></div></div></div>

header.php

URL タイトル

サイトの説明

Page 59: Wordpressで自分好みのテーマを作る

URL タイトル

サイトの説明

Page 60: Wordpressで自分好みのテーマを作る

header.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head><meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title> <?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?>

</title><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css” /><style type="text/css”> #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-ltr.jpg“) }</style><?php wp_head(); ?>

</head><body><div id="page"><div id="header" role="banner"><div id="headerimg"> <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1> <div class="description"><?php bloginfo('description'); ?></div></div></div>

bloginfoのマニュアルを見てみる

Page 61: Wordpressで自分好みのテーマを作る

header.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head><meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title> <?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?>

</title><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css” /><style type="text/css”> #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-ltr.jpg“) }</style><?php wp_head(); ?>

</head><body><div id="page"><div id="header" role="banner"><div id="headerimg"> <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1> <div class="description"><?php bloginfo('description'); ?></div></div></div>

ドキュメントの場所は?

Page 62: Wordpressで自分好みのテーマを作る

wordpress codex 検 索

Page 63: Wordpressで自分好みのテーマを作る

次に、WordPressループの説明

Page 64: Wordpressで自分好みのテーマを作る

<?php get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

index.php(or loop.php)WordPressループ(Main Contents)

footer

header

sidebar

maincontents

Page 65: Wordpressで自分好みのテーマを作る

繰り返し

記事タイトル日付

本文

カテゴリ、コメント

Page 66: Wordpressで自分好みのテーマを作る

<?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<h2><a href="<?php the_permalink() ?>“ ><?php the_title(); ?></a></h2>

<small><?php the_time(__('F jS, Y', 'kubrick')) ?></small> <div class="entry">

<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?> </div> <p class="postmetadata">

<?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>

<?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?> </p> </div>

<?php endwhile; ?>

WordPressループ

Page 67: Wordpressで自分好みのテーマを作る

<?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<h2><a href="<?php the_permalink() ?>“ ><?php the_title(); ?></a></h2>

<small><?php the_time(__('F jS, Y', 'kubrick')) ?></small> <div class="entry">

<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?> </div> <p class="postmetadata">

<?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>

<?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?> </p> </div>

<?php endwhile; ?>

WordPressループ

投稿の数だけループ

投稿がある間Loopする 投稿1つ分の準備

Page 68: Wordpressで自分好みのテーマを作る

<?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<h2><a href="<?php the_permalink() ?>“ ><?php the_title(); ?></a></h2>

<small><?php the_time(__('F jS, Y', 'kubrick')) ?></small> <div class="entry">

<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?> </div> <p class="postmetadata">

<?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>

<?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?> </p> </div>

<?php endwhile; ?>

WordPressループ

タイトル

本文

Page 69: Wordpressで自分好みのテーマを作る

<?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<h2><a href="<?php the_permalink() ?>“ ><?php the_title(); ?></a></h2>

<small><?php the_time(__('F jS, Y', 'kubrick')) ?></small> <div class="entry">

<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?> </div> <p class="postmetadata">

<?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>

<?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?> </p> </div>

<?php endwhile; ?>

タイトル

本文

全部理解しないといけないの?

Page 70: Wordpressで自分好みのテーマを作る

・すべてのコードを理解する必要はない。・イメージにあったテーマを見つけてきて、 それをカスタマイズすればよい。

Page 71: Wordpressで自分好みのテーマを作る

default

他のファイルは?

Page 72: Wordpressで自分好みのテーマを作る

default

← not foundページ アーカイブページ

コメントページ

← 共通関数用

← 画像一覧ページ

言語関連ファイル

← リンクページ← 特定の1ページ

← スクリーンショット← 検索ページ

← 1投稿分の詳細ページ

Page 73: Wordpressで自分好みのテーマを作る

default

← not foundページ アーカイブページ

コメントページ

← 共通関数用

← 画像一覧ページ

言語関連ファイル

← リンクページ← 特定の1ページ

← スクリーンショット← 検索ページ

← 1投稿分の詳細ページ

あとは調べれればなんとかなる!

Page 74: Wordpressで自分好みのテーマを作る

終わり