2012-10-12 79 views
1

我已經在我的WordPress網站的functions.php文件中定義下面的函數,它應該給打開評論或關閉的選項:如果陣列中的其他陣列

$wp_customize->add_section('display_comments', array(
    'title'  => 'Comments', 
    'priority' => 36, 
)); 

$wp_customize->add_setting('mytheme_comments'); 

$wp_customize->add_control('mytheme_comments', array(
    'label' => 'Comments on or off', 
    'section' => 'display_comments', 
    'type' => 'select', 
    'default' => 'Off', 
    'choices' => array(
     'value1' => 'On', 
     'value2' => 'Off', 
     ), 
)); 

然後我有這個在我的單PHP文件,這是顯示一個人的博客文章頁面:

<?php if (get_theme_mod ('mytheme_comments' == 'On')) : ?> 
<?php comments_template(); ?> 
<?php elseif (get_theme_mod ('mytheme_comments' == 'Off')) : ?> 
<?php endif ?> 

的意見是默認關閉的,但選擇從下拉菜單「上」,沒有任何效果。

任何想法我可能做錯了什麼?

回答

3

您shuld改變

if (get_theme_mod ('bistheme_comments' == 'On')) 

if (get_theme_mod ('bistheme_comments') == 'On' ) 

elseif (get_theme_mod ('mytheme_comments' == 'Off')) 

elseif (get_theme_mod ('mytheme_comments') == 'Off' ) 

更好的方法來重寫您的代碼

$var = get_theme_mod('mytheme_comments'); 
if ($var == 'On') { 
    comments_template(); 
} else if ($var == 'Off') { 
    // Var is Off 
} else { 
    // Var was not set 
} 
+0

感謝您的支持。我已經嘗試過進行更改,但由於某些原因,它仍未註冊更改。 – user18577

+0

@ user18577我可以看到你的更新代碼..將完整的代碼添加到pastbin – Baba

+0

當然,在這裏你去:http://pastebin.com/Yuka0nRK – user18577