我正在使用ACF 我的WP 3.3.1应用程序中的插件,我使用the_field
方法在整个站点的许多地方使用。我特别使用的一个地方是幻灯片/旋转木马,如下所示:
<img alt="" src="<?php the_field(\'slideshow_image\'); ?>" />
wp_postmeta
在_wp_attachment_image_alt
图元键。。。但是,我不确定如何访问此。使命感the_field
“image\\u alt”不起作用,并且文档有限。我正在使用ACF 我的WP 3.3.1应用程序中的插件,我使用the_field
方法在整个站点的许多地方使用。我特别使用的一个地方是幻灯片/旋转木马,如下所示:
<img alt="" src="<?php the_field(\'slideshow_image\'); ?>" />
wp_postmeta
在_wp_attachment_image_alt
图元键。。。但是,我不确定如何访问此。使命感the_field
“image\\u alt”不起作用,并且文档有限。您需要设置ACF字段以返回图像对象而不是URL。然后,可以使用以下代码检索图像和alt文本:
<?php $slideshow_image = get_field(\'slideshow_image\');
// Check for alt text - if there isn\'t any, use the image title
$alt = ($slideshow_image[\'alt\']?$slideshow_image[\'alt\']:$slideshow_image[\'title\']);
// Return full size image
$url = $slideshow_image[\'url\']; ?>
<img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" />
如果要返回不同大小的图像,可以使用sizes数组而不是url:// Return image thumbnail
$url = $slideshow_image[\'sizes\'][\'thumbnail\'];
自定义显示下的文档:http://www.advancedcustomfields.com/resources/image/编辑:
此解决方案仅适用于ACF 3.3.7及以上版本。另一种方法是返回图像/附件ID,然后使用wp_get_attachment_image()
返回完整图像HTML。此处的文档:http://codex.wordpress.org/Function_Reference/wp_get_attachment_image
在标题中。php我可以执行以下操作:<base href=\"<?php echo get_bloginfo(\'template_url\');?>/\"/> 这样我可以保持布局图像路径的相对性。 <img src=\"imgs/img.png\"/> 而不是 <img src=\"<?php echo get_bloginfo(\'template_url\');?>\"/> 基本url的设置是否有任何缺