次の switch ステートメントがあります。
switch($post->post_type) {
default:
echo 'default';
<?php }
本質的に、これは可能な限り基本的なものです。はpost->post_type
、アイテム (WordPress) の投稿タイプに応じて文字列を返す単純な変数です。
私ができるようにしたいのは、誰かが配列を行うのと非常によく似たように、switchステートメントにプラグインすることです-次のように:
function add_extra_fruits($fruits) {
$extra_fruits = array(
'plums',
'kiwis',
'tangerines',
'pepino melons'
);
// combine the two arrays
$fruits = array_merge($extra_fruits, $fruits);
return $fruits;
}
add_filter('add_fruits', 'add_extra_fruits');
関数を使用しarray_merge()
ます。
次の例を試してみました。
switch ( true /* we're comparing a boolean, not the post type! */ ) {
case has_action( "basey_loop_single_$post->post_type" ) :
do_action( "basey_loop_single_$post->post_type" );
break;
default :
// default post layout
}
しかし、これが次のように、サンプルアクションを渡すことで私が求めていることを達成するかどうかはわかりません:
function basey_loop_single_page_output() {
echo 'test';
}
add_action('basey_loop_single_page', 'basey_loop_single_page_output');
$post->post_type
指定されているとおり、条件が満たされた場合は何も返しません。誰でもこれにどのようにアプローチできるか考えていますか? 簡単に言うと、これは PHP の核となる質問 (switch ステートメントへのプラグインに関するもの) ですが、明らかに、ここでの専門用語の一部は WordPress 向けです。
ありがとう!