2011-10-07 44 views
0
<?php 
if (get_option('to_breadcrumbs') == 'Yes'); 
if (get_option('to_breadcrumbs') != 'No') { 
    if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); 
} ?> 

我很新的PHP。有什麼關於上面的代碼應該修復?這些if語句有什麼不對嗎?

+1

是,第2行沒有任何意義。你想怎麼做? – str

+0

如果首先做什麼?看起來不太有用。 – John

+0

這是什麼鏈接? http://stackoverflow.com/questions/7691953/php-to-show-by-default-call-or-array如果該答案沒有解決您的問題,請不要將其標記爲已接受。等待另一個。 –

回答

1

它在語法上是正確的。

if (get_option('to_breadcrumbs') == 'Yes'); 

這是不需要的。沒有代碼從外面跑。

if (get_option('to_breadcrumbs') != 'No') { 
    if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); 
} 

這會運行並執行一些操作。你可以縮短它到一個簡單的陳述。

if (get_option('to_breadcrumbs') != 'No' and function_exists('dimox_breadcrumbs')) 
    dimox_breadcrumbs(); 

但是,您可以根據自己的意願對其進行編碼,但上面的行是大多數PHP程序員的首選。

+0

'get_option('to_breadcrumbs')'會在wordpress中觸發選項過濾器並實際執行代碼,但不需要比較。 – hakre

1

第二行

if (get_option('to_breadcrumbs') == 'Yes'); 

沒有意義,它不會做任何東西,除了通話get_option() - 但條件不採取行動。

其餘的似乎理智(不知道什麼功能實際上做當然

2

我覺得語法是正確的,但邏輯是不對的。 get_option('to_breadcrumbs') != 'No'表示與get_option('to_breadcrumbs') == 'Yes'相同,假定值可以是或不是。

+0

雖然他們是兩個不同的陳述。 –

0

我會寫這樣的:

<?ph 
//I'm assuming here that only you only want to run it if the to_breadcrumbs option is equal to yes. 
if(get_option('to_breadcrumbs') == 'Yes' AND function_exists('dimox_breadcrumbs')){ 
    dimox_breadcrumbs(); 
} 
?>