Woocommerce,如何从数据库中获取图像

时间:2014-06-27 21:07:47

标签: php wordpress slider woocommerce

我尝试将最近添加的产品图片放入滑块。我安装了Woocommerce。我编写此代码用于从数据库获取图像路径。但它需要所有图像样本图像等并返回403禁止错误(http://localhost/projectname/wp-content/uploads/2014/06/Screen-shot-2014-06-27-at-17.56.10.png%3Cbr%3E)403禁止

那么我怎样才能获得最新添加的产品图片?

这是我的代码

$sql = "SELECT * FROM wp_bapk_posts WHERE post_type = 'attachment' ORDER BY `ID` DESC LIMIT 4";
                mysql_select_db('houseok3_wor0879');
                $retval = mysql_query( $sql, $conn );
                if(! $retval )
                {
                  die('Could not get data: ' . mysql_error());
                }

                while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
                {
                    $var = $row['ID'];
                    $sql2 = "SELECT * FROM wp_bapk_postmeta WHERE post_id = '".$var."' AND meta_key = '_wp_attached_file' ORDER BY `post_id` LIMIT 4";
                    mysql_select_db('houseok3_wor0879');
                    $retval2 = mysql_query( $sql2, $conn );
                    while($row2 = mysql_fetch_array($retval2, MYSQL_ASSOC))
                    {
                        $file = $row2['meta_value']."<br>";
                        echo "<img src='wp-content/uploads/".$file."' alt=\"". $alt . "\" ".$imageAddParams. $kb_pz .">\n";
                    }
                }

0 个答案:

没有答案