2012-10-20 25 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()功能应该在年底