質問編集履歴
5
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,9 +39,6 @@
|
|
39
39
|
### 試したこと
|
40
40
|
|
41
41
|
|
42
|
-
・●●●●
|
43
|
-

|
44
|
-
|
45
42
|
・エラー内容について
|
46
43
|
該当ページに「Cannot redeclare current_crumb_tag()」というエラーがあることから、関数の重複を疑いました。
|
47
44
|
しかし、functions.phpに追記した関数名の「create_post_type」を別の文字に置き換えても結果は同じでした。
|
4
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,159 +1,145 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
カスタム投稿タイプでページを作成したいです。
|
3
|
-
しかし、アクセスするとエラーが出てページの内容を表示できません。
|
4
|
-
|
5
|
-
この症状は「the thor」という特定のテーマだけで起こります。
|
6
|
-
|
7
|
-
### 発生している問題・エラーメッセージ
|
8
|
-
作成したカスタム投稿のURLにアクセスするとエラーが出ます。
|
9
|
-
|
10
|
-
```
|
11
|
-
Fatal error: Cannot redeclare current_crumb_tag() (previously declared in /home/
|
12
|
-
```
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
'
|
24
|
-
'
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
・
|
43
|
-
|
44
|
-
|
45
|
-
・
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
/
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
$current_crumb_tag
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
$
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
```
|
146
|
-
「breadcrumb.php on line 156」と末尾にあることから今度は同じファイルの156行目付近に何かあるのか探してみましたが、よくわかりませんでした。(上記に周辺コードも載せています)
|
147
|
-
|
148
|
-
関数名を定義する部分だけでなく、途中に登場する「$current_crumb_tag」にも何か処理を加えないといけないのでしょうか
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
### 補足情報(FW/ツールのバージョンなど)
|
153
|
-
・WordPress5.4.2
|
154
|
-
・PHP 7.3.18
|
155
|
-
・プラグインはすべて停止状態
|
156
|
-
|
157
|
-
有料テーマなのでサポートにも問い合わせていますが、回答が得られていない状態です・・・
|
158
|
-
|
1
|
+
### 前提・実現したいこと
|
2
|
+
カスタム投稿タイプでページを作成したいです。
|
3
|
+
しかし、アクセスするとエラーが出てページの内容を表示できません。
|
4
|
+
|
5
|
+
この症状は「the thor」という特定のテーマだけで起こります。
|
6
|
+
|
7
|
+
### 発生している問題・エラーメッセージ
|
8
|
+
作成したカスタム投稿のURLにアクセスするとエラーが出ます。
|
9
|
+
|
10
|
+
```
|
11
|
+
Fatal error: Cannot redeclare current_crumb_tag() (previously declared in /home/www/fuga/wp-content/themes/the-thor/inc/front/breadcrumb.php:22) in /home/www/fuga/wp-content/themes/the-thor/inc/front/breadcrumb.php on line 22
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
### 該当のソースコード
|
16
|
+
子テーマのfunctions.phpに下記のコードを追加してカスタム投稿タイプの追加を行いました。
|
17
|
+
|
18
|
+
```php
|
19
|
+
function create_post_type() {
|
20
|
+
$exampleSupports = [ // supports のパラメータを設定する配列(初期値だと title と editor のみ投稿画面で使える)
|
21
|
+
'title', // 記事タイトル
|
22
|
+
'editor', // 記事本文
|
23
|
+
'thumbnail', // アイキャッチ画像
|
24
|
+
'revisions' // リビジョン
|
25
|
+
];
|
26
|
+
register_post_type( 'example', // カスタム投稿名
|
27
|
+
array(
|
28
|
+
'label' => 'テストカスタム投稿', // 管理画面の左メニューに表示されるテキスト
|
29
|
+
'public' => true, // 投稿タイプをパブリックにするか否か
|
30
|
+
'has_archive' => true, // アーカイブを有効にするか否か
|
31
|
+
'menu_position' => 5, // 管理画面上でどこに配置するか今回の場合は「投稿」の下に配置
|
32
|
+
'supports' => $exampleSupports // 投稿画面でどのmoduleを使うか的な設定
|
33
|
+
)
|
34
|
+
);
|
35
|
+
}
|
36
|
+
add_action( 'init', 'create_post_type' ); // アクションに上記関数をフックします
|
37
|
+
```
|
38
|
+
|
39
|
+
### 試したこと
|
40
|
+
|
41
|
+
|
42
|
+
・●●●●
|
43
|
+

|
44
|
+
|
45
|
+
・エラー内容について
|
46
|
+
該当ページに「Cannot redeclare current_crumb_tag()」というエラーがあることから、関数の重複を疑いました。
|
47
|
+
しかし、functions.phpに追記した関数名の「create_post_type」を別の文字に置き換えても結果は同じでした。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
breadcrumb.php全体のコードは文字数オーバーになるので
|
52
|
+
ここには記載できませんでした。
|
53
|
+
|
54
|
+
###追加で試したこと1
|
55
|
+
hayato7様の回答をもとに、
|
56
|
+
親テーマの該当関数が定義されているファイルに
|
57
|
+
「if ( function_exists( 'current_crumb_tag' )」
|
58
|
+
のようなif文を追記しました。
|
59
|
+
|
60
|
+
```php
|
61
|
+
//breadcrumb.php
|
62
|
+
|
63
|
+
//中略
|
64
|
+
|
65
|
+
|
66
|
+
if ( function_exists( 'current_crumb_tag' ) ) {
|
67
|
+
function current_crumb_tag( $current_permalink, $current_text = '', $args = array(), $current_class = 'breadcrumb__item breadcrumb__item-current' ) {
|
68
|
+
$args = wp_parse_args( $args );
|
69
|
+
$args = ( object )$args;
|
70
|
+
$current_class = $current_class ? ' class="' . esc_attr( $current_class ) . '"': '';
|
71
|
+
$start_anchor_tag = $current_permalink ? '<a href="' . $current_permalink . '">': '';
|
72
|
+
$end_anchor_tag = $current_permalink ? '</a>' : '';
|
73
|
+
$current_before = '<li' . $current_class . '>' . $start_anchor_tag . '';
|
74
|
+
$current_crumb_tag = $current_text;
|
75
|
+
$current_after = '' . $end_anchor_tag . '</li>';
|
76
|
+
if ( get_query_var( 'paged' ) ) {
|
77
|
+
if ( is_paged() || is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
|
78
|
+
$current_after = ' (ページ' . get_query_var( 'paged' ) . ')' . $current_after;
|
79
|
+
}
|
80
|
+
|
81
|
+
} elseif ( ( is_page() || is_single() ) && get_query_var( 'page' ) ) {
|
82
|
+
$current_after = ' (ページ' . get_query_var( 'page' ) . ')' . $current_after;
|
83
|
+
}
|
84
|
+
|
85
|
+
return $current_before . $current_crumb_tag . $current_after;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
//中略
|
90
|
+
|
91
|
+
//元から書いてあっためちゃくちゃ長いif文の途中
|
92
|
+
} else {
|
93
|
+
$post_type_object = get_post_type_object( get_post_type() );
|
94
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_post_type_archive_link( get_post_type() ) . '">' . $post_type_object->label . '</a></li>';
|
95
|
+
$taxonomies = get_object_taxonomies( get_post_type() );
|
96
|
+
$category_term = '';
|
97
|
+
|
98
|
+
foreach ( $taxonomies as $taxonomy ) {
|
99
|
+
$taxonomy_obj = get_taxonomy( $taxonomy );
|
100
|
+
if ( true == $taxonomy_obj->hierarchical ) {
|
101
|
+
$category_term = $taxonomy_obj;
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
if ( $category_term ) {
|
107
|
+
$terms = get_the_terms( $post->ID, $category_term->name );
|
108
|
+
|
109
|
+
if ( $terms ) {
|
110
|
+
if ( !$terms || is_wp_error( $terms ) )
|
111
|
+
$terms = array();
|
112
|
+
|
113
|
+
$terms = array_values( $terms );
|
114
|
+
$term = $terms[ 0 ];
|
115
|
+
|
116
|
+
if ( $term->parent != 0 ) {
|
117
|
+
$ancestors = array_reverse( get_ancestors( $term->term_id, $term->taxonomy ) );
|
118
|
+
foreach ( $ancestors as $ancestor ) {
|
119
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_term_link( $ancestor, $term->taxonomy ) . '">' . get_term( $ancestor, $term->taxonomy )->name . '</a></li>';
|
120
|
+
}
|
121
|
+
}
|
122
|
+
//156行目↓↓
|
123
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_term_link( $term, $term->taxonomy ) . '">' . $term->name . '</a></li>';
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
$breadcrumb_html .= current_crumb_tag( get_the_permalink( $single->ID ), get_the_title( $single->ID ) );
|
128
|
+
}
|
129
|
+
//中略
|
130
|
+
```
|
131
|
+
|
132
|
+
「breadcrumb.php on line 156」と末尾にあることから今度は同じファイルの156行目付近に何かあるのか探してみましたが、よくわかりませんでした。(上記に周辺コードも載せています)
|
133
|
+
|
134
|
+
関数名を定義する部分だけでなく、途中に登場する「$current_crumb_tag」にも何か処理を加えないといけないのでしょうか
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
### 補足情報(FW/ツールのバージョンなど)
|
139
|
+
・WordPress5.4.2
|
140
|
+
・PHP 7.3.18
|
141
|
+
・プラグインはすべて停止状態
|
142
|
+
|
143
|
+
有料テーマなのでサポートにも問い合わせていますが、回答が得られていない状態です・・・
|
144
|
+
|
159
145
|
どなたか知恵を貸していただけないでしょうか。
|
3
試したことをもう少しわかりやすく修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -63,7 +63,11 @@
|
|
63
63
|
ここには記載できませんでした。
|
64
64
|
|
65
65
|
###追加で試したこと1
|
66
|
+
hayato7様の回答をもとに、
|
66
|
-
親テーマの該当関数が定義されているファイルに
|
67
|
+
親テーマの該当関数が定義されているファイルに
|
68
|
+
「if ( function_exists( 'current_crumb_tag' )」
|
69
|
+
のようなif文を追記しました。
|
70
|
+
|
67
71
|
```php
|
68
72
|
//breadcrumb.php
|
69
73
|
|
@@ -95,7 +99,7 @@
|
|
95
99
|
|
96
100
|
//中略
|
97
101
|
|
98
|
-
//めちゃくちゃ長いif文の途中
|
102
|
+
//元から書いてあっためちゃくちゃ長いif文の途中
|
99
103
|
} else {
|
100
104
|
$post_type_object = get_post_type_object( get_post_type() );
|
101
105
|
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_post_type_archive_link( get_post_type() ) . '">' . $post_type_object->label . '</a></li>';
|
2
試したことの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,6 +62,89 @@
|
|
62
62
|
breadcrumb.php全体のコードは文字数オーバーになるので
|
63
63
|
ここには記載できませんでした。
|
64
64
|
|
65
|
+
###追加で試したこと1
|
66
|
+
親テーマの該当関数が定義されているファイルにif文を追記しました。
|
67
|
+
```php
|
68
|
+
//breadcrumb.php
|
69
|
+
|
70
|
+
//中略
|
71
|
+
|
72
|
+
|
73
|
+
if ( function_exists( 'current_crumb_tag' ) ) {
|
74
|
+
function current_crumb_tag( $current_permalink, $current_text = '', $args = array(), $current_class = 'breadcrumb__item breadcrumb__item-current' ) {
|
75
|
+
$args = wp_parse_args( $args );
|
76
|
+
$args = ( object )$args;
|
77
|
+
$current_class = $current_class ? ' class="' . esc_attr( $current_class ) . '"': '';
|
78
|
+
$start_anchor_tag = $current_permalink ? '<a href="' . $current_permalink . '">': '';
|
79
|
+
$end_anchor_tag = $current_permalink ? '</a>' : '';
|
80
|
+
$current_before = '<li' . $current_class . '>' . $start_anchor_tag . '';
|
81
|
+
$current_crumb_tag = $current_text;
|
82
|
+
$current_after = '' . $end_anchor_tag . '</li>';
|
83
|
+
if ( get_query_var( 'paged' ) ) {
|
84
|
+
if ( is_paged() || is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
|
85
|
+
$current_after = ' (ページ' . get_query_var( 'paged' ) . ')' . $current_after;
|
86
|
+
}
|
87
|
+
|
88
|
+
} elseif ( ( is_page() || is_single() ) && get_query_var( 'page' ) ) {
|
89
|
+
$current_after = ' (ページ' . get_query_var( 'page' ) . ')' . $current_after;
|
90
|
+
}
|
91
|
+
|
92
|
+
return $current_before . $current_crumb_tag . $current_after;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
//中略
|
97
|
+
|
98
|
+
//めちゃくちゃ長いif文の途中
|
99
|
+
} else {
|
100
|
+
$post_type_object = get_post_type_object( get_post_type() );
|
101
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_post_type_archive_link( get_post_type() ) . '">' . $post_type_object->label . '</a></li>';
|
102
|
+
$taxonomies = get_object_taxonomies( get_post_type() );
|
103
|
+
$category_term = '';
|
104
|
+
|
105
|
+
foreach ( $taxonomies as $taxonomy ) {
|
106
|
+
$taxonomy_obj = get_taxonomy( $taxonomy );
|
107
|
+
if ( true == $taxonomy_obj->hierarchical ) {
|
108
|
+
$category_term = $taxonomy_obj;
|
109
|
+
break;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
if ( $category_term ) {
|
114
|
+
$terms = get_the_terms( $post->ID, $category_term->name );
|
115
|
+
|
116
|
+
if ( $terms ) {
|
117
|
+
if ( !$terms || is_wp_error( $terms ) )
|
118
|
+
$terms = array();
|
119
|
+
|
120
|
+
$terms = array_values( $terms );
|
121
|
+
$term = $terms[ 0 ];
|
122
|
+
|
123
|
+
if ( $term->parent != 0 ) {
|
124
|
+
$ancestors = array_reverse( get_ancestors( $term->term_id, $term->taxonomy ) );
|
125
|
+
foreach ( $ancestors as $ancestor ) {
|
126
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_term_link( $ancestor, $term->taxonomy ) . '">' . get_term( $ancestor, $term->taxonomy )->name . '</a></li>';
|
127
|
+
}
|
128
|
+
}
|
129
|
+
//156行目↓↓
|
130
|
+
$breadcrumb_html .= '<li' . $li_class . '><a href="' . get_term_link( $term, $term->taxonomy ) . '">' . $term->name . '</a></li>';
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
$breadcrumb_html .= current_crumb_tag( get_the_permalink( $single->ID ), get_the_title( $single->ID ) );
|
135
|
+
}
|
136
|
+
//中略
|
137
|
+
```
|
138
|
+
すると今度は次のようなエラーに変わりました。
|
139
|
+
```
|
140
|
+
Fatal error: Uncaught Error: Call to undefined function current_crumb_tag() in /home/●●●●/www/●●●●/wp-content/themes/the-thor/inc/front/breadcrumb.php:156 Stack trace: #0 /home/●●●●/www/●●●●/wp-content/themes/the-thor/header.php(273): fit_breadcrumb() #1 /home/●●●●/www/●●●●/wp-includes/template.php(723): require_once('/home/smart-mob...') #2 /home/●●●●/www/●●●●/wp-includes/template.php(672): load_template('/home/smart-mob...', true) #3 /home/●●●●/www/●●●●/wp-includes/general-template.php(41): locate_template(Array, true) #4 /home/●●●●/www/●●●●/wp-content/themes/the-thor/single.php(1): get_header() #5 /home/●●●●/www/●●●●/wp-includes/template-loader.php(106): include('/home/smart-mob...') #6 /home/●●●●/www/●●●●/wp-blog-header.php(19): require_once('/home/smart-mob...') #7 /home/●●●●/www/●●●●/index.php(17): require('/home/smart-mob...') #8 {main} thrown in /home/●●●●/www/●●●●/wp-content/themes/the-thor/inc/front/breadcrumb.php on line 156
|
141
|
+
```
|
142
|
+
「breadcrumb.php on line 156」と末尾にあることから今度は同じファイルの156行目付近に何かあるのか探してみましたが、よくわかりませんでした。(上記に周辺コードも載せています)
|
143
|
+
|
144
|
+
関数名を定義する部分だけでなく、途中に登場する「$current_crumb_tag」にも何か処理を加えないといけないのでしょうか
|
145
|
+
|
146
|
+
|
147
|
+
|
65
148
|
### 補足情報(FW/ツールのバージョンなど)
|
66
149
|
・WordPress5.4.2
|
67
150
|
・PHP 7.3.18
|
1
プラグインは全部停止している旨を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,6 +65,7 @@
|
|
65
65
|
### 補足情報(FW/ツールのバージョンなど)
|
66
66
|
・WordPress5.4.2
|
67
67
|
・PHP 7.3.18
|
68
|
+
・プラグインはすべて停止状態
|
68
69
|
|
69
70
|
有料テーマなのでサポートにも問い合わせていますが、回答が得られていない状態です・・・
|
70
71
|
|