我有一个WordPress博客,作为web应用程序的子目录托管。WordPress的安装是不变的,修改是在主题级别完成的。web应用程序主页需要显示最近的博客文章。因此,我有以下代码来显示最近的帖子:
$array = array();
$query = "SELECT * FROM wp_posts WHERE post_status=:publish AND post_type=:post_type";
$stmt = $this->dbj->prepare($query);
$stmt->execute(array(
\':publish\' => \'publish\',
\':post_type\' => \'post\'
));
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$id = $row["ID"];
if ($row["post_name"] == \'\') {
$slug = $row["ID"];
} else {
$slug = $row["post_name"];
}
$content1 = strip_tags($row["post_content"]);
$image_prepare = $this->dbj->prepare(\'SELECT
wp_postmeta.meta_id,
wp_postmeta.post_id,
wp_postmeta.meta_key,
wp_postmeta.meta_value
FROM
wp_postmeta
INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id
WHERE
wp_postmeta.meta_key = :meta_key
AND wp_posts.post_parent = :pid\');
$image_prepare->execute(
array(
\':pid\' => $id,
\':meta_key\' => \'_wp_attached_file\'
)
);
$image_fetch = $image_prepare->fetchAll();
foreach ($image_fetch as $image_row) {
$image_name = $row[\'post_title\'];
$image_path = $image_row[\'meta_value\'];
}
if (strlen($content1) > 200) {
$content = substr($content1, 0, 200) . \'...\';
} else {
$content = nl2br($content1);
}
$array[] = array(
\'image_path\' => $image_path,
\'image_name\' => $image_name,
\'slug\' => $row["post_name"],
\'content\' => $content,
\'title\' => $row[\'post_title\']
);
}
return $array;
}
我正在获取全尺寸图像url。我在我的
functions.php
主题中的文件:
add_theme_support(\'post-thumbnails\');
add_image_size(\'home-size\', 214, 300);
add_image_size(\'home-featured\', 300, 300);
add_image_size(\'jobs-thumb\', 50, 75);
问题是,上传目录中已调整大小的图像并不总是
image-name-300x300.jpg
对于
home-featured
. 相反,它们具有随机的高度值,这取决于图像在文件名中的比率(例如:
image-name-300x220.jpg
). 我重新生成了缩略图,但文件名仍然相同。我如何获得
\'home-featured\'
对于上述解决方案?