質問編集履歴

3

最新の子テーマFunction.phpを記載。Debugモードを実施。

2018/04/26 06:44

投稿

TAKEZO6
TAKEZO6

スコア6

test CHANGED
File without changes
test CHANGED
File without changes

2

Wordpressダッシュボード画面でのコードが白くなっているものが解決。

2018/04/26 06:44

投稿

TAKEZO6
TAKEZO6

スコア6

test CHANGED
File without changes
test CHANGED
@@ -240,7 +240,7 @@
240
240
 
241
241
 
242
242
 
243
- ここに問題に対ししたことを記載しくだ
243
+ エディターはTerapadを使っおりましたが、ちらの文字コードをUTF-8Nに変えたころ、Wordpressダッシュボード画面でみる各コードが真っ白になっいるという現象は解決れました
244
244
 
245
245
 
246
246
 

1

function.phpコードの追記、テーマ名の入力

2018/04/13 06:57

投稿

TAKEZO6
TAKEZO6

スコア6

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,23 @@
26
26
 
27
27
 
28
28
 
29
-
29
+ さらにFTPソフトで子テーマ中のcontent.phpを見ると必要なコードが記載されているのですが、Wordpressダッシュボードのテーマの編集⇒子テーマ⇒content.phpを見ると真っ白になってしまっています。(関係があるのか不明)
30
+
31
+
32
+
33
+ (4月13日 追記)
34
+
35
+ 使い方よくわかっておらず大変失礼しました。
36
+
37
+
38
+
39
+ 以下に子テーマのfunction.phpを貼り付けます。
40
+
41
+
42
+
43
+ また使用しているテーマはTwenty Twelveというものを使っており、子テーマを作成して編集しております。
44
+
45
+ https://ja.wordpress.org/themes/twentytwelve/
30
46
 
31
47
 
32
48
 
@@ -36,7 +52,7 @@
36
52
 
37
53
  ```
38
54
 
39
- さらにFTPソフトで子テーマ中のcontent.phpを見ると必要なコードが記載されているのですが、Wordpressダッシュボードのテーマの編集⇒子テーマ⇒content.phpを見ると真っ白になってしまっています。(関係があるのか不明)
55
+
40
56
 
41
57
  ```
42
58
 
@@ -46,9 +62,175 @@
46
62
 
47
63
 
48
64
 
65
+ ```
66
+
67
+ <?php
68
+
69
+ /**
70
+
71
+ * Sets the post excerpt length to 40 words.
72
+
73
+ *
74
+
75
+ * To override this length in a child theme, remove the filter and add your own
76
+
77
+ * function tied to the excerpt_length filter hook.
78
+
79
+ */
80
+
81
+ function twentytwelve_excerpt_length( $length ) {
82
+
49
- ```ここに言語名を入力
83
+ return 40;
84
+
50
-
85
+ }
86
+
87
+ add_filter( 'excerpt_length', 'twentytwelve_excerpt_length' );
88
+
89
+
90
+
91
+ if ( ! function_exists( 'twentytwelve_continue_reading_link' ) ) :
92
+
93
+ /**
94
+
95
+ * Returns a "Continue Reading" link for excerpts
96
+
97
+ */
98
+
99
+ function twentytwelve_continue_reading_link() {
100
+
101
+ return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '続きを読む <span class="meta-nav">→</span>', 'twentytwelve' ) . '</a>';
102
+
103
+ }
104
+
105
+ endif; // twentytwelve_continue_reading_link
106
+
107
+
108
+
109
+ /**
110
+
111
+ * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentytwelve_continue_reading_link().
112
+
113
+ *
114
+
115
+ * To override this in a child theme, remove the filter and add your own
116
+
117
+ * function tied to the excerpt_more filter hook.
118
+
119
+ */
120
+
121
+ function twentytwelve_auto_excerpt_more( $more ) {
122
+
123
+ return ' …' . twentytwelve_continue_reading_link();
124
+
125
+ }
126
+
127
+ add_filter( 'excerpt_more', 'twentytwelve_auto_excerpt_more' );
128
+
129
+
130
+
131
+ /**
132
+
133
+ * Adds a pretty "Continue Reading" link to custom post excerpts.
134
+
135
+ *
136
+
137
+ * To override this link in a child theme, remove the filter and add your own
138
+
139
+ * function tied to the get_the_excerpt filter hook.
140
+
141
+ */
142
+
143
+ function twentytwelve_custom_excerpt_more( $output ) {
144
+
145
+ if ( has_excerpt() && ! is_attachment() ) {
146
+
147
+ $output .= twentytwelve_continue_reading_link();
148
+
149
+ }
150
+
51
- 子テーマのFunction.php
151
+ return $output;
152
+
153
+ }
154
+
155
+ add_filter( 'get_the_excerpt', 'twentytwelve_custom_excerpt_more' );
156
+
157
+ ?>
158
+
159
+
160
+
161
+ add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
162
+
163
+
164
+
165
+ function theme_enqueue_styles()
166
+
167
+
168
+
169
+ { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
170
+
171
+
172
+
173
+ }
174
+
175
+
176
+
177
+ //H2見出しを判別する正規表現を定数にする
178
+
179
+ define('H2_REG', '/<h2.*?>/i');//H2見出しのパターン
180
+
181
+
182
+
183
+ //本文中にH2見出しが最初に含まれている箇所を返す(含まれない場合はnullを返す)
184
+
185
+ //H3-H6しか使っていない場合は、h2部分を変更してください
186
+
187
+ function get_h2_included_in_body( $the_content ){
188
+
189
+ if ( preg_match( H2_REG, $the_content, $h2results )) {//H2見出しが本文中にあるかどうか
190
+
191
+ return $h2results[0];
192
+
193
+ }
194
+
195
+ }
196
+
197
+
198
+
199
+ function add_ads_before_1st_h2($the_content) {
200
+
201
+ if ( is_single() ) {//固定ページも表示する場合はis_singular()にする
202
+
203
+ ob_start();//バッファリング
204
+
205
+ get_template_part('ad-in-body');//広告貼り付け用に作成したテンプレート
206
+
207
+ $ad_template = ob_get_clean();
208
+
209
+ $h2result = get_h2_included_in_body( $the_content );//本文にH2タグが含まれていれば取得
210
+
211
+ if ( $h2result ) {//H2見出しが本文中にある場合のみ
212
+
213
+ //最初のH2の手前に広告を挿入(最初のH2を置換)
214
+
215
+ $count = 1;
216
+
217
+ $the_content = preg_replace(H2_REG, $ad_template.$h2result, $the_content, 1);
218
+
219
+ }
220
+
221
+ }
222
+
223
+ return $the_content;
224
+
225
+ }
226
+
227
+ add_filter('the_content','add_ads_before_1st_h2');
228
+
229
+
230
+
231
+ ?>
232
+
233
+
52
234
 
53
235
  ```
54
236
 
@@ -63,119 +245,3 @@
63
245
 
64
246
 
65
247
  ### 補足情報(FW/ツールのバージョンなど)
66
-
67
-
68
-
69
- ここにより詳細な情報を記載してください。
70
-
71
- Function.phpには以下のコードを入力しています。
72
-
73
-
74
-
75
- <?php
76
-
77
- /**
78
-
79
- * Sets the post excerpt length to 40 words.
80
-
81
- *
82
-
83
- * To override this length in a child theme, remove the filter and add your own
84
-
85
- * function tied to the excerpt_length filter hook.
86
-
87
- */
88
-
89
- function twentytwelve_excerpt_length( $length ) {
90
-
91
- return 40;
92
-
93
- }
94
-
95
- add_filter( 'excerpt_length', 'twentytwelve_excerpt_length' );
96
-
97
-
98
-
99
- if ( ! function_exists( 'twentytwelve_continue_reading_link' ) ) :
100
-
101
- /**
102
-
103
- * Returns a "Continue Reading" link for excerpts
104
-
105
- */
106
-
107
- function twentytwelve_continue_reading_link() {
108
-
109
- return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '続きを読む <span class="meta-nav">→</span>', 'twentytwelve' ) . '</a>';
110
-
111
- }
112
-
113
- endif; // twentytwelve_continue_reading_link
114
-
115
-
116
-
117
- /**
118
-
119
- * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentytwelve_continue_reading_link().
120
-
121
- *
122
-
123
- * To override this in a child theme, remove the filter and add your own
124
-
125
- * function tied to the excerpt_more filter hook.
126
-
127
- */
128
-
129
- function twentytwelve_auto_excerpt_more( $more ) {
130
-
131
- return ' …' . twentytwelve_continue_reading_link();
132
-
133
- }
134
-
135
- add_filter( 'excerpt_more', 'twentytwelve_auto_excerpt_more' );
136
-
137
-
138
-
139
- /**
140
-
141
- * Adds a pretty "Continue Reading" link to custom post excerpts.
142
-
143
- *
144
-
145
- * To override this link in a child theme, remove the filter and add your own
146
-
147
- * function tied to the get_the_excerpt filter hook.
148
-
149
- */
150
-
151
- function twentytwelve_custom_excerpt_more( $output ) {
152
-
153
- if ( has_excerpt() && ! is_attachment() ) {
154
-
155
- $output .= twentytwelve_continue_reading_link();
156
-
157
- }
158
-
159
- return $output;
160
-
161
- }
162
-
163
- add_filter( 'get_the_excerpt', 'twentytwelve_custom_excerpt_more' );
164
-
165
- ?>
166
-
167
-
168
-
169
- add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
170
-
171
-
172
-
173
- function theme_enqueue_styles()
174
-
175
-
176
-
177
- { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
178
-
179
-
180
-
181
- }