<?php
mysql_connect("localhost", "xxxxxx", "xxxxx") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());
$data = mysql_query("SELECT
p1.*,
wm2.meta_value
FROM
xxxxx_posts p1
LEFT JOIN
xxxxxx_postmeta wm1
ON (
wm1.post_id = p1.id
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = \'_thumbnail_id\'
)
LEFT JOIN
xxxxx_postmeta wm2
ON (
wm1.meta_value = wm2.post_id
AND wm2.meta_key = \'_xxxxxx_attached_file\'
AND wm2.meta_value IS NOT NULL
)
WHERE
p1.post_status=\'publish\'
AND p1.post_type=\'post\'
ORDER BY
p1.post_date DESC")
or die(mysql_error());
Print "<div class=\'widgetlist\'>";
while($info = mysql_fetch_array( $data ))
{
Print "<ul><li><a href=\'http://xxxxxxx.com/en/?p=".$info[\'ID\'] . "\'>";
Print $info[\'post_title\'];
Print "</a> </li></ul> ";
}
Print "</div>";
?>
如何在wordpress post中获取特色图片//////php code for image fetching
2 个回复
SO网友:StenW
要获得特色图像,请使用the_post_thumbnail( $size, $attr );
.
二者都$size
和$attr
是可选的,它们通常在主题中定义。
如果不是,您可以按以下方式设置:
$default_attr = array(
\'src\' => $src,
\'class\' => "attachment-$size",
\'alt\' => trim(strip_tags( $attachment->post_excerpt )),
\'title\' => trim(strip_tags( $attachment->post_title ))
);
$size = array( 32, 32 );
附言:我希望这就是你要找的,你发布的代码没有多大意义。你想做什么?SO网友:s_ha_dum
如何在wordpress post中获取特色图像[?]
echo get_the_post_thumbnail( $post_id );
或者,在一个适当的循环中,the_post_thumbnail();
但我有一种感觉,这个问题遗漏了一些信息。您没有使用任何核心功能,并且没有解释为什么,也没有解释为什么不使用。例如WP_Query
编写自己的SQL要容易得多。使用$wpdb
对象将比创建自己的MySQL连接更容易。使用get_permalink
比手动创建链接更简单、更可靠。
参考文献
http://codex.wordpress.org/Function_Reference/get_the_post_thumbnailhttp://codex.wordpress.org/Function_Reference/the_post_thumbnail
结束