質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,4 +39,190 @@
|
|
39
39
|
```
|
40
40
|
こちらのコードでsingle.phpを用意しています。
|
41
41
|
|
42
|
-
原因のわかる方、宜しくお願いいたします。
|
42
|
+
原因のわかる方、宜しくお願いいたします。
|
43
|
+
|
44
|
+
追記
|
45
|
+
|
46
|
+
オリジナルテーマです。
|
47
|
+
|
48
|
+
サイドバー
|
49
|
+
```UTF-8
|
50
|
+
<?php
|
51
|
+
/**
|
52
|
+
* The template for displaying the sidebar
|
53
|
+
* @package WordPress
|
54
|
+
*/
|
55
|
+
?>
|
56
|
+
<div id="nav" class="sidebar2">
|
57
|
+
<div class="side_inr1">
|
58
|
+
<div class="side_title1">
|
59
|
+
<img src="">
|
60
|
+
<div class="blog">
|
61
|
+
<?php query_posts('posts_per_page=5'); ?>
|
62
|
+
<?php if (have_posts()):while(have_posts()):the_post(); ?>
|
63
|
+
|
64
|
+
<a href="<?php echo get_permalink(); ?>"><h2><p><?php the_title(); ?></p></h2></a>
|
65
|
+
|
66
|
+
<?php endwhile; endif; ?>
|
67
|
+
</div>
|
68
|
+
</div>
|
69
|
+
</div>
|
70
|
+
<div class="side_inr2">
|
71
|
+
<div class="side_title2">
|
72
|
+
<img src="">
|
73
|
+
</div>
|
74
|
+
<img src="">
|
75
|
+
<img src="">
|
76
|
+
</div>
|
77
|
+
<div class="side_inr3">
|
78
|
+
<div class="side_title3">
|
79
|
+
<img src="">
|
80
|
+
</div>
|
81
|
+
<a href=""></a>
|
82
|
+
<a href=""></a>
|
83
|
+
<a href=""></a>
|
84
|
+
<a href="/contact-2/"><img src=""></a>
|
85
|
+
</div>
|
86
|
+
<div class="side_fb">
|
87
|
+
<iframe src=""></iframe>
|
88
|
+
</div>
|
89
|
+
</div>
|
90
|
+
```
|
91
|
+
|
92
|
+
ヘッダー
|
93
|
+
```UTF-8
|
94
|
+
<?php
|
95
|
+
/**
|
96
|
+
* The template for displaying the header
|
97
|
+
* @package WordPress
|
98
|
+
*/
|
99
|
+
?>
|
100
|
+
<!DOCTYPE html>
|
101
|
+
<html>
|
102
|
+
<head>
|
103
|
+
<meta charset="utf-8">
|
104
|
+
<meta name="keywords" content="">
|
105
|
+
<meta name="description" content="">
|
106
|
+
<title></title>
|
107
|
+
<?php wp_head(); ?>
|
108
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
|
109
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
110
|
+
<link href="<?php echo get_stylesheet_directory_uri() ?>/style.css" rel="stylesheet" type="text/css" media="all">
|
111
|
+
</head>
|
112
|
+
|
113
|
+
<body>
|
114
|
+
<header>
|
115
|
+
<a href=""><h1><img class="logo2" src=""></h1></a>
|
116
|
+
</div>
|
117
|
+
|
118
|
+
</header>
|
119
|
+
```
|
120
|
+
footer.php
|
121
|
+
|
122
|
+
```UTF-8
|
123
|
+
<?php
|
124
|
+
/**
|
125
|
+
* The template for displaying the footer
|
126
|
+
* @package WordPress
|
127
|
+
*/
|
128
|
+
?>
|
129
|
+
<div class="cb"></div>
|
130
|
+
</div>
|
131
|
+
|
132
|
+
|
133
|
+
<?php wp_footer(); ?>
|
134
|
+
</body>
|
135
|
+
</html>
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
function.php
|
140
|
+
```UTF-8
|
141
|
+
<?php
|
142
|
+
|
143
|
+
// ウィジェット
|
144
|
+
register_sidebar();
|
145
|
+
|
146
|
+
add_theme_support( 'post-thumbnails', array( 'post' ) );
|
147
|
+
set_post_thumbnail_size( 100, 100, true );
|
148
|
+
|
149
|
+
|
150
|
+
function new_excerpt_more($post) {
|
151
|
+
return '<a href="'. get_permalink($post->ID) . '">' . '...続きを読む' . '</a>';
|
152
|
+
}
|
153
|
+
add_filter('excerpt_more', 'new_excerpt_more');
|
154
|
+
|
155
|
+
|
156
|
+
?>
|
157
|
+
<?php
|
158
|
+
// functions.phpに以下を追記
|
159
|
+
add_action('admin_menu', 'add_custom_fields');
|
160
|
+
add_action('save_post', 'save_custom_fields');
|
161
|
+
|
162
|
+
// 記事ページと固定ページでカスタムフィールドを表示
|
163
|
+
function add_custom_fields() {
|
164
|
+
add_meta_box( 'my_sectionid', 'カスタムフィールド', 'my_custom_fields', 'post');
|
165
|
+
add_meta_box( 'my_sectionid', 'カスタムフィールド', 'my_custom_fields', 'page');
|
166
|
+
}
|
167
|
+
|
168
|
+
function my_custom_fields() {
|
169
|
+
global $post;
|
170
|
+
$keywords = get_post_meta($post->ID,'keywords',true);
|
171
|
+
$description = get_post_meta($post->ID,'description',true);
|
172
|
+
|
173
|
+
echo '<p>キーワード(半角カンマ区切り)<br>';
|
174
|
+
echo '<input type="text" name="keywords" value="'.esc_html($keywords).'" size="60" /></p>';
|
175
|
+
|
176
|
+
echo '<p>ページの説明(description)160文字以内<br>';
|
177
|
+
echo '<input type="text" style="width: 600px;height: 40px;" name="description" value="'.esc_html($description).'" maxlength="160" /></p>';
|
178
|
+
}
|
179
|
+
|
180
|
+
// カスタムフィールドの値を保存
|
181
|
+
function save_custom_fields( $post_id ) {
|
182
|
+
if(!empty($_POST['keywords']))
|
183
|
+
update_post_meta($post_id, 'keywords', $_POST['keywords'] );
|
184
|
+
else delete_post_meta($post_id, 'keywords');
|
185
|
+
|
186
|
+
if(!empty($_POST['description']))
|
187
|
+
update_post_meta($post_id, 'description', $_POST['description'] );
|
188
|
+
else delete_post_meta($post_id, 'description');
|
189
|
+
}
|
190
|
+
|
191
|
+
function my_description() {
|
192
|
+
|
193
|
+
// カスタムフィールドの値を読み込む
|
194
|
+
$custom = get_post_custom();
|
195
|
+
if(!empty( $custom['keywords'][0])) {
|
196
|
+
$keywords = $custom['keywords'][0];
|
197
|
+
}
|
198
|
+
if(!empty( $custom['description'][0])) {
|
199
|
+
$description = $custom['description'][0];
|
200
|
+
}
|
201
|
+
?>
|
202
|
+
<?php if(is_home()): // トップページ ?>
|
203
|
+
<meta name="robots" content="index, follow" />
|
204
|
+
<meta name="keywords" content="トップページに表示させるkeywords(半角カンマ区切り)">
|
205
|
+
<meta name="description" content="トップページに表示させるdescription" />
|
206
|
+
<?php elseif(is_single()): // 記事ページ ?>
|
207
|
+
<meta name="robots" content="index, follow" />
|
208
|
+
<meta name="keywords" content="<?php echo $keywords ?>">
|
209
|
+
<meta name="description" content="<?php echo $description ?>">
|
210
|
+
<?php elseif(is_page()): // 固定ページ ?>
|
211
|
+
<meta name="robots" content="index, follow" />
|
212
|
+
<meta name="keywords" content="<?php echo $keywords ?>">
|
213
|
+
<meta name="description" content="<?php echo $description ?>">
|
214
|
+
<?php elseif (is_category()): // カテゴリーページ ?>
|
215
|
+
<meta name="robots" content="index, follow" />
|
216
|
+
<meta name="description" content="<?php single_cat_title(); ?>の記事一覧" />
|
217
|
+
<?php elseif (is_tag()): // タグページ ?>
|
218
|
+
<meta name="robots" content="noindex, follow" />
|
219
|
+
<meta name="description" content="<?php single_tag_title("", true); ?>の記事一覧" />
|
220
|
+
<?php elseif(is_404()): // 404ページ ?>
|
221
|
+
<meta name="robots" content="noindex, follow" />
|
222
|
+
<title><?php echo 'お探しのページが見つかりませんでした'; ?></title>
|
223
|
+
<?php else: // その他ページ ?>
|
224
|
+
<meta name="robots" content="noindex, follow" />
|
225
|
+
<?php endif; ?>
|
226
|
+
<?php
|
227
|
+
}
|
228
|
+
```
|