「カテゴリと、カスタムフィールドの値」を組み合わせた場合の条件分岐方法を教えてください。
次のような書き方をかやってみたのですけれど間違っているみたいです。
php
1<?php $ctfanimal = get_post_meta($post->ID,'select',true); ?> 2 3 if( in_category('neko') && empty( $ctfanimal ) ) { 4 get_template_part('off-neko'); 5 }elseif( in_category('neko') && get_post_meta($post->ID,'select',true) == 'on') { 6 get_template_part('on-neko'); 7 8 }elseif( ( in_category('inu') && empty( $ctfanimal ) ) { 9 get_template_part('off-inu'); 10 }elseif( in_category('inu') && get_post_meta($post->ID,'select',true) == 'on') { 11 get_template_part('on-inu'); 12 13<?php endif;?>
通常postのカテゴリには
・neko
・inu
カスタムフィールド名「select」の値には
・on
・空の場合(offという値にはできません)
があります。
組み合わせは4通りです。
例えば「nekoカテゴリでonのときは、on-neko.phpを呼び出す」ということです。
上記のコードだと何がダメなのでしょうか?
宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。