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("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 に答える