2014-01-13 69 views
0

我想分配使用php的图像的动态路径。设置值在img标签在php

虽然试图用呼应

echo '<img src="'.$guild_image_path.'"/>'; 

我得到了正确的路径的路径。

但是,如果我在我的应用程序中应用相同,我没有得到图像路径。

请参考下我的代码,

printf('<span class="byline"><span class="rounded_image"><a href="%4$s" rel="author"><?php echo '<img src="'.$guild_image_path.'"/>'; ?>%5$s</a></span></span>', 
       esc_url(get_permalink()), 
     esc_attr(get_the_date('c')), 
     esc_html(get_the_date()), 
     esc_url(get_author_posts_url(get_the_author_meta('ID'))), 
     get_the_author() 
    ); 

请帮我做到这一点。

回答

0

尝试在printf()之前使用error_log或echo进行调试,以确保您获取变量$guild_image_path中的值。

error_log('image path'.$guild_image_path); 

echo $guild_image_path; 
+0

好这就是问题所在。 – user2681579

1

为什么你在printf中使用的回声? 第二个printf是arleady PHP,所以你不需要再打开php标签。

printf('<span class="byline"><span class="rounded_image"><a href="%4$s" rel="author"><img src="'.$guild_image_path.'"/>%5$s</a></span></span>', 
      esc_url(get_permalink()), 
    esc_attr(get_the_date('c')), 
    esc_html(get_the_date()), 
    esc_url(get_author_posts_url(get_the_author_meta('ID'))), 
    get_the_author() 
); 

了解更多的printf:http://www.php.net/manual/ru/function.printf.php