2012-10-20 26 views
0

使用VSlider - WordPress中我使用的常見問題提供的功能:簡單的PHP語法 - 如何獲得使用VSlider的名稱使用-ID後

<?php if(function_exists('vslider')){ vslider('vslider_options'); } ?>

我試圖做到這一點。所以它知道要獲得後ID作爲它的名字。但它不工作。

<?php if(function_exists('vslider')){ vslider('<?php the_ID(); ?>'); } ?>

+0

唉返回一個字符串做到這一點 - 'the_ID()'是那些一個又一個愚蠢的Wordpress功能,打印到屏幕上,而不是返回一個值。需要找到合適的方法來返回值。 –

回答

1

不能嵌套<?php ?>內一個已經打開<?php ?>。這是不受支持的,而且語法無效。只需調用該函數即可。

顯然,the_ID()是打印到輸出緩衝區而不返回其值的那些Wordpress函數之一。要獲得編號返回它可以在一個函數中有用,請使用get_the_ID()來代替。

<?php if(function_exists('vslider')){ vslider(get_the_ID()); } ?> 

當表達爲正確縮進的代碼時,語法問題變得更加明顯。

<?php 
if (function_exists('vslider')){ 
    vslider(get_the_ID()); 
} 
?> 
+0

優秀。這絕對有效,第一次。你對get_the_id完全正確。我也嘗試過,但我的PHP語法又一次。非常感謝。我會標記這個,但顯然我必須在15 ... – KingLouie

0

是的,你可以通過刪除PHP標籤

<?php if(function_exists('vslider')){ vslider('<?php the_ID(); ?>'); } ?> 

should be 

<?php if(function_exists('vslider')){ vslider(the_ID()); } ?> 

和你the_ID()功能應該在年底