0

我在使用自定义字段正确输出滑块中的图像目录时遇到了问题。我正在使用的代码如下:

<div class="container">
    <?php
    //path or directory where the images are stored
    $directory = "echo get_post_meta($post->ID, 'directory', true)";

    //read all files with a .jpg extension
    $images = glob($directory . "*.jpg");

    //output the required HTML code to display the images in the gallery
    foreach($images as $image)
    {
        echo '<div class="content"><div><a href="'.$image.'"><img src="'.$image.'" width="120" height="80" alt="this is a test" class="thumb" /></a></div></div>'."\n";
    }
    ?>
</div>

我想要动态输出的值是 $directory = "",它通常类似于 $directory = "images/product1/"。我将自定义字段“目录”设置为 images/product1/。有任何想法吗?谢谢您的帮助!

4

1 回答 1

0

看起来问题出在这一行:

$directory = "echo get_post_meta($post->ID, 'directory', true)";

将导致尝试像这样进行 glob:

glob("echo get_post_meta($post->ID, 'directory', true)*.jpg");

这显然是无效的。

相反,您实际上应该调用该get_post_meta()函数

$directory = get_post_meta($post->ID, 'directory', true);
于 2012-10-22T17:41:44.097 回答