質問編集履歴
2
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,9 +9,10 @@
|
|
9
9
|
##解決したいこと
|
10
10
|
投稿ごとにコメントがしっかり振り分けられるようにしたいと思っています。
|
11
11
|
|
12
|
-
解決策が思い浮かぶ方は、どんなアドバイスでも構いませんので力を貸していただきたいです。
|
12
|
+
解決策が思い浮かぶ方は、どんなアドバイスでも構いませんので力を貸していただきたいです。
|
13
|
+
```PHP
|
14
|
+
【funtions.php】
|
13
15
|
<?php
|
14
|
-
|
15
16
|
//概要(抜粋)の文字数
|
16
17
|
function my_length($length) {
|
17
18
|
return 50;
|
@@ -213,7 +214,8 @@
|
|
213
214
|
}
|
214
215
|
```
|
215
216
|
|
217
|
+
``` PHP
|
216
|
-
|
218
|
+
【comments.php】
|
217
219
|
<div id="comment_area">
|
218
220
|
<div class="comment_post">
|
219
221
|
|
@@ -255,5 +257,4 @@
|
|
255
257
|
</div>
|
256
258
|
<?php endif; ?>
|
257
259
|
|
258
|
-
|
259
260
|
```
|
1
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,251 @@
|
|
9
9
|
##解決したいこと
|
10
10
|
投稿ごとにコメントがしっかり振り分けられるようにしたいと思っています。
|
11
11
|
|
12
|
-
解決策が思い浮かぶ方は、どんなアドバイスでも構いませんので力を貸していただきたいです。
|
12
|
+
解決策が思い浮かぶ方は、どんなアドバイスでも構いませんので力を貸していただきたいです。```functions.php
|
13
|
+
<?php
|
14
|
+
|
15
|
+
//概要(抜粋)の文字数
|
16
|
+
function my_length($length) {
|
17
|
+
return 50;
|
18
|
+
}
|
19
|
+
add_filter('excerpt_mblength','my_length');
|
20
|
+
|
21
|
+
//概要(抜粋)の省略記号
|
22
|
+
function my_more($more) {
|
23
|
+
return '…';
|
24
|
+
}
|
25
|
+
add_filter('excerpt_more', 'my_more');
|
26
|
+
|
27
|
+
|
28
|
+
//コンテンツの最大幅
|
29
|
+
if ( !isset( $content_width ) ) {
|
30
|
+
$content_width = 747;
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
//YouTubeのビデオ:<div>でマークアップ
|
36
|
+
function ytwrapper($return, $data, $url) {
|
37
|
+
if ($data->provider_name == 'YouTube') {
|
38
|
+
return '<div class="ytvideo">'.$return.'</div>';
|
39
|
+
} else {
|
40
|
+
return $return;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
add_filter('oembed_dataparse','ytwrapper',10,3);
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
//YouTubeのビデオ:キャッシュをクリア
|
48
|
+
//function clear_ytwrapper($post_id) {
|
49
|
+
// global $wp_embed;
|
50
|
+
// $wp_embed->delete_oembed_caches($post_id);
|
51
|
+
//}
|
52
|
+
//add_action('pre_post_update', 'clear_ytwrapper');
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
//アイキャッチ画像
|
57
|
+
add_theme_support( 'post-thumbnails' );
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
//編集画面の設定
|
62
|
+
function editor_setting($init) {
|
63
|
+
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre';
|
64
|
+
|
65
|
+
$style_formats = array(
|
66
|
+
array(
|
67
|
+
'title' => '補足情報',
|
68
|
+
'block' => 'div',
|
69
|
+
'classes' => 'point'
|
70
|
+
),
|
71
|
+
array(
|
72
|
+
'title' => '注意書き',
|
73
|
+
'block' => 'div',
|
74
|
+
'classes' => 'attention'
|
75
|
+
)
|
76
|
+
);
|
77
|
+
|
78
|
+
$init['style_formats'] = json_encode( $style_formats );
|
79
|
+
|
80
|
+
|
81
|
+
return $init;
|
82
|
+
}
|
83
|
+
add_filter('tiny_mce_before_init', 'editor_setting');
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
//スタイルメニューを有効化
|
88
|
+
function add_stylemenu( $buttons ){
|
89
|
+
array_splice( $buttons, 1, 0, 'styleselect' );
|
90
|
+
return $buttons;
|
91
|
+
}
|
92
|
+
add_filter( 'mce_buttons_2', 'add_stylemenu' );
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
// エディタスタイルシート
|
97
|
+
add_editor_style();
|
98
|
+
add_editor_style( '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' );
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
// サムネイル画像
|
103
|
+
function mythumb( $size ) {
|
104
|
+
|
105
|
+
if( has_post_thumbnail() ) {
|
106
|
+
$postthumb = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );
|
107
|
+
$url = $postthumb[0];
|
108
|
+
} else {
|
109
|
+
$url = get_template_directory_uri() . '/mainimage.jpg';
|
110
|
+
}
|
111
|
+
|
112
|
+
return $url;
|
113
|
+
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// トグルボタン
|
120
|
+
function navbtn_scripts() {
|
121
|
+
|
122
|
+
wp_enqueue_script( 'navbtn-script', get_template_directory_uri() .'/navbtn.js', array('jquery') );
|
123
|
+
}
|
124
|
+
add_action( 'wp_enqueue_scripts', 'navbtn_scripts' );
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
// ウィジェットエリア
|
129
|
+
register_sidebar( array(
|
130
|
+
'id' => 'submenu',
|
131
|
+
'name' => ' サブメニュー',
|
132
|
+
'description' => 'サイドバーに表示するウィジェットを指定。',
|
133
|
+
'before_widget' => '<aside id="%1$s" class="mymenu widget %2$s">',
|
134
|
+
'after_widget' => '</aside>',
|
135
|
+
'before_title' => '<h2 class="widgettitle">',
|
136
|
+
'after_title' => '</h2>'
|
137
|
+
) );
|
138
|
+
|
139
|
+
register_sidebar( array(
|
140
|
+
'id' => 'ad',
|
141
|
+
'name' => '広告',
|
142
|
+
'description' => 'サイドバーに表示する広告を指定。',
|
143
|
+
'before_widget' => '<aside id="%1$s" class="myad mymenu widget %2$s">',
|
144
|
+
'after_widget' => '</aside>',
|
145
|
+
'before_title' => '<h2 class="widgettitle">',
|
146
|
+
'after_title' => '</h2>'
|
147
|
+
) );
|
148
|
+
|
149
|
+
register_sidebars( 2, array(
|
150
|
+
'name' => __( 'Side Widget %d' ),
|
151
|
+
'id' => 'side-widget',
|
152
|
+
'before_widget' => '<li class="widget-container">',
|
153
|
+
'after_widget' => '</li>',
|
154
|
+
'before_title' => '<h3>',
|
155
|
+
'after_title' => '</h3>',
|
156
|
+
) );
|
157
|
+
|
158
|
+
|
159
|
+
// 検索フォーム
|
160
|
+
add_theme_support( 'html5', array('search-form') );
|
161
|
+
|
162
|
+
//「コメントを急いで投稿しすぎているようです。」の解除
|
163
|
+
remove_filter('comment_flood_filter', 'wp_throttle_comment_flood', 10, 3);
|
164
|
+
|
165
|
+
|
166
|
+
//srcset削除
|
167
|
+
add_filter( 'wp_calculate_image_srcset_meta', '__return_null' );
|
168
|
+
|
169
|
+
|
170
|
+
//画像挿入時の添付ファイルのページの選択肢を消す
|
171
|
+
function media_script_buffer_start() {
|
172
|
+
ob_start();
|
173
|
+
}
|
174
|
+
add_action( 'post-upload-ui', 'media_script_buffer_start' );
|
175
|
+
|
176
|
+
function media_script_buffer_get() {
|
177
|
+
$scripts = ob_get_clean();
|
178
|
+
$scripts = preg_replace( '#<option value="post">.*?</option>#s', '', $scripts );
|
179
|
+
echo $scripts;
|
180
|
+
}
|
181
|
+
add_action( 'print_media_templates', 'media_script_buffer_get' );
|
182
|
+
|
183
|
+
//attachment_id=ページに404を返す
|
184
|
+
add_action( 'template_redirect', 'gs_attachment_template_redirect' );
|
185
|
+
function gs_attachment_template_redirect() {
|
186
|
+
if ( is_attachment() ) { // 添付ファイルの個別ページなら
|
187
|
+
global $wp_query;
|
188
|
+
$wp_query->set_404();
|
189
|
+
status_header(404);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
//hetnryを削除する
|
194
|
+
function remove_hentry( $classes ) {
|
195
|
+
$classes = array_diff($classes, array('hentry'));
|
196
|
+
return $classes;
|
197
|
+
}
|
198
|
+
|
199
|
+
add_filter('post_class', 'remove_hentry');
|
200
|
+
|
201
|
+
|
202
|
+
//固定ページにカテゴリーを出す
|
203
|
+
add_action('init','add_categories_for_pages');
|
204
|
+
function add_categories_for_pages(){
|
205
|
+
register_taxonomy_for_object_type('category', 'page');
|
206
|
+
}
|
207
|
+
add_action( 'pre_get_posts', 'nobita_merge_page_categories_at_category_archive' );
|
208
|
+
function nobita_merge_page_categories_at_category_archive( $query ) {
|
209
|
+
|
210
|
+
if ( $query->is_category== true && $query->is_main_query() ) {
|
211
|
+
$query->set('post_type', array( 'post', 'page', 'nav_menu_item'));
|
212
|
+
}
|
213
|
+
}
|
214
|
+
```
|
215
|
+
|
216
|
+
```comments.php
|
217
|
+
<div id="comment_area">
|
218
|
+
<div class="comment_post">
|
219
|
+
|
220
|
+
<?php $args = array(
|
221
|
+
'title_reply' => '口コミを投稿する',
|
222
|
+
'label_submit' => '口コミを送信する',
|
223
|
+
'fields' => array(
|
224
|
+
'author' => '<p class="comment-form-author">' .
|
225
|
+
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' placeholder="*お名前" /></p>',
|
226
|
+
),
|
227
|
+
'comment_field' => '<p class="comment-form-comment">' . '<textarea id="comment" name="comment" cols="50" rows="6" aria-required="true"' . $aria_req . ' placeholder="*口コミの内容" /></textarea></p>',
|
228
|
+
);
|
229
|
+
comment_form( $args ); ?>
|
230
|
+
</div>
|
231
|
+
<div class="posted_comments">
|
232
|
+
<?php if(have_comments()): ?>
|
233
|
+
<h3 id="comments">投稿された口コミ</h3>
|
234
|
+
<div class="comments-list">
|
235
|
+
<?php $comments_per_page = 10;
|
236
|
+
$comments = get_comments( array( 'status' => 'approve' ) );
|
237
|
+
?>
|
238
|
+
<?php wp_list_comments( array (
|
239
|
+
'per_page' => $comments_per_page,
|
240
|
+
'reverse_top_level' => false
|
241
|
+
), $comments ); ?>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
</div>
|
246
|
+
<?php endif; ?>
|
247
|
+
</div>
|
248
|
+
</div>
|
249
|
+
|
250
|
+
|
251
|
+
<?php if(get_comment_pages_count() > 1) : ?>
|
252
|
+
<div>
|
253
|
+
<?php previous_comments_link('前のコメント'); ?>
|
254
|
+
<?php next_comments_link('次のコメント'); ?>
|
255
|
+
</div>
|
256
|
+
<?php endif; ?>
|
257
|
+
|
258
|
+
|
259
|
+
```
|