2010-12-08 15 views
0

自分のワードプレスの単一ページにカスタムフィールドを出力したい。 基本的には、関連するクリエイティブ共通ライセンスの種類をページに出力します。したがって、キーcc-licenseのカスタムフィールドは基本的に1つの値のみを持つことができますが、その値は6つのクリエイティブ共通ライセンスのいずれかでなければなりません。WordPress条件付きカスタムフィールド

キーcc-licenseの値をすでに挿入しているとします。だからここに私のコードです:

<?php 
$nilai = get_post_meta($post->ID, 'cc-license', true); 
echo $nilai; //just want to check the output,its ok! 
if ($nilai = 'Attribution Non-commercial Share Alike') { ?> 
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>      
<?php } ?> 

問題は、私は任意のテキストに値を変更した場合、それはまだ条件文にHTMLコードを実装しています。どの部分が間違っていますか?

答えて

0

=私はあなただけで見逃しているかもしれないと思う、これを試してみてください

<?php 
    $nilai = get_post_meta($post->ID, 'cc-license', true); 

    echo $nilai; //just want to check the output,its ok! 

    if ($nilai == 'Attribution Non-commercial Share Alike') : ?> 

     <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br /> 
     This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a> 

    <?php endif; 
?>