2013-08-22 34 views
0

我使用這個代碼:語法錯誤在WordPress

if (in_category('finance')) { 
     include(TEMPLATEPATH.'/category1.php'); 
} elseif (in_category('2')) { 
     include(TEMPLATEPATH.'/category2.php'); 
} else { 
     include(TEMPLATEPATH.'/default.php'); 
} 

一切工作正常。當我有名稱財務類別時,將使用category1.php中的模板。

但現在我想包括一個選項,要求這樣的基於特定模板文件:

<?php echo $up_options->category1; ?> 

所以我插入選項請求代碼爲第一碼是這樣的:

if (in_category('finance')) { 
     include(TEMPLATEPATH.'/$up_options->category1;'); 
} elseif (in_category('2')) { 
     include(TEMPLATEPATH.'/single2.php'); 
} else { 
     include(TEMPLATEPATH.'/category1.php'); 
} 

我得到下面的錯誤與上面的代碼:

[function.include]: failed to open stream: Invalid argument in..... 

真是一個ppreciate任何幫助。

謝謝。

回答

0

$ up_options是一個變量,但是您將它用作字符串。試着做這樣的:

if (in_category('finance')) { 
    include(TEMPLATEPATH . '/' . $up_options->category1); 
} 
+0

謝謝,忍者。不幸的是你的代碼無法正常工作,同樣的錯誤仍時有發生。 –

0

你包括'/$up_options->category1;'會使用的是單引號解析爲string。通過將其更改爲雙引號「/$up_options->category1;"嘗試

我不認爲你需要在最後添加;,所以這將是更合適的

"/$up_options->category1"

第二個選項已經被@ninja建議 -

TEMPLATEPATH . '/' . $up_options->category1

+0

感謝swapnesh。沒FO工作我。我有另一個錯誤。 –

+0

@AnabeleRosemary echo $ up_options-> category1;'?並粘貼完整的錯誤代碼 – swapnesh

+0

其調用名稱爲category1.php和category2.php的模板。這裏的錯誤:「解析錯誤:語法錯誤,在第31行D:\ 0-SERVER \ iwpserver \ htdocs \ wordpress \ wp-content \ themes \ MARIO \ category.php中出現意外的T_LNUMBER」 –