【问题标题】:Wordpress Custom Field Template- Display multiple images from file field of a specific keyWordpress 自定义字段模板 - 显示来自特定键的文件字段的多个图像
【发布时间】:2011-11-30 06:47:43
【问题描述】:

我正在使用 Wordpress 自定义字段模板插件 - http://wordpress.org/extend/plugins/custom-field-template/

我创建了一些这样的文件

[slideshow]
type = file
relation = true
label = Images For the Slide show?

[slideshow]
type = file
relation = true
hideKey = true

[slideshow]
type = file
relation = true
hideKey = true

[slideshow]
type = file
relation = true
hideKey = true

我想显示来自文件字段的图像列表,例如

<?php $slide_images = get_post_meta($post->ID, 'slideshow', false); ?>
   <ul id="slideshow">
                <?php foreach($slide_images as $slide_image) {
                    echo '<li>'.$slide_image.'</li>';
       } ?>
  <ul>

参考: http://www.designfaire.com/2010/05/custom-post-types-and-custom-field-template-in-wordpress-3-0-beta-2/

http://wordpress.org/support/topic/plugin-custom-field-template-file-and-image-display?replies=13

【问题讨论】:

  • 卡在哪里了,哪里出错了?
  • 没有错误现在它只打印图像 ID 我想获取图像wp_get_attachment_url("Image ID", 'full');
  • 如果是这样,您可以使用 wp_get_attachment_url($slide_image, 'full');而不仅仅是 $slide_image。
  • 得到了解决方案,我做了类似的东西&lt;?php $slide_images = get_post_meta($post-&gt;ID, 'slideshow', false); ?&gt; &lt;ul id="slideshow"&gt; &lt;?php foreach($slide_images as $key=&gt;$slide_image) { $slide_url = wp_get_attachment_image($slide_image, 'full'); echo '&lt;li&gt;'.$slide_url.'&lt;/li&gt;'; } ?&gt;谢谢你的帮助

标签: php wordpress custom-fields


【解决方案1】:

找到解决办法

<?php $slide_images = get_post_meta($post->ID, 'slideshow', false); ?>
            <ul id="slideshow">
                <?php  foreach($slide_images as $key=>$slide_image) {
                    $slide_url = wp_get_attachment_image($slide_image, 'full');
                    echo '<li>'.$slide_url.'</li>';
} ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    相关资源
    最近更新 更多