问问题
281 次
3 回答
2
首先,确保不存在返回未格式化数据的其他函数。
如果没有,这里有一个快速而肮脏的正则表达式来提取 URL:
$str = '<li><a href="http://foo.com/wp-content/uploads/2011/07/picture.png">picture</a></li>';
preg_match('~\shref="([^"]++)"~', $str, $matches);
$url = $matches[1];
于 2011-07-13T05:59:33.593 回答
1
于 2011-07-13T05:57:33.733 回答
1
多动手怎么办?- http://wp-snippets.com/727/custom-display-of-links-blogroll/
$links = $wpdb->get_results("SELECT * FROM $wpdb->links ORDER BY link_name ASC");
//start going through all the links and get the required values for each link
foreach ($links as $link) {
$linkurl=$link->link_url;
$linkdesc=$link->link_description;
$linkname=$link->link_name;
$linkimage=$link->link_image;
$linknotes=$link->link_notes; }
Wordpress 有许多内置功能。您可能无需从代码中破解它就可以获取图像 URL 本身。
http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
如果您知道附件 ID,这将返回 url
$imgData = wp_get_attachment_image_src( $attachment_id);
echo $imgData[0];
于 2011-07-13T06:16:00.073 回答