Php中Wordpress自定义字段的问题
我在使用自定义字段正确输出滑块中图像的目录时遇到问题。我使用的代码如下:Php中Wordpress自定义字段的问题,php,html,wordpress,custom-fields,Php,Html,Wordpress,Custom Fields,我在使用自定义字段正确输出滑块中图像的目录时遇到问题。我使用的代码如下: <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
<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 = "echo get_post_meta($post->ID, 'directory', true)";
将导致尝试像这样全球化:
glob("echo get_post_meta($post->ID, 'directory', true)*.jpg");
这显然是无效的
实际上,您应该调用get\u post\u meta()
函数
$directory = get_post_meta($post->ID, 'directory', true);
谢谢你的编辑。谢谢你!完美的口吃,对我来说很有用。再次感谢你的帮助!