Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress中获取文章的图像url?_Php_Wordpress_Pinterest - Fatal编程技术网

Php 如何在wordpress中获取文章的图像url?

Php 如何在wordpress中获取文章的图像url?,php,wordpress,pinterest,Php,Wordpress,Pinterest,我正在为Wordpress开发Pinterest pinit插件。Pinterest pinit按钮需要图像URL和post URL。。。如何获取图像URL 我使用了以下代码,但没有成功: $pid=get_the_ID(); $image_id = get_post_thumbnail_id($pid); $image_url = wp_get_attachment_image_src($image_id); echo $image_url[0]; 有人能帮忙吗 你也试过这个吗 $url =

我正在为Wordpress开发Pinterest pinit插件。Pinterest pinit按钮需要图像URL和post URL。。。如何获取图像URL

我使用了以下代码,但没有成功:

$pid=get_the_ID();
$image_id = get_post_thumbnail_id($pid);
$image_url = wp_get_attachment_image_src($image_id);
echo $image_url[0];

有人能帮忙吗

你也试过这个吗

$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
<img src="<?php echo $url; ?>" />
$url=wp\u get\u attachment\u url(get\u post\u缩略图\u id($post->id));
" />

您也可以这样使用,$catposts是一个以帖子为特色的图像查询

$category_id = 'your_category_id'; $NUMBEROFPOSTS = '4'; $catposts = get_posts('category='.$category_id."&order=DESC&numberposts=".$NUMBEROFPOSTS); 

foreach ($catposts as $item) :

     echo '<li class="active" style="height: 100px; width: 71px;">';

     echo '<a href="'.get_permalink( $item->ID ).'">';

     echo '<img src="'.wp_get_attachment_url( get_post_thumbnail_id($item->ID)).'">';

     echo '</a>';

     echo '</li>';

endforeach;
$category_id='your_category_id';$NUMBEROFPOSTS='4';$catposts=get_posts('category='.$category_id.&order=DESC&numberposts=“.NUMBEROFPOSTS”);
foreach($catposts作为$item):
echo'
  • '; 回声'; 回音“
  • ”; endforeach;
    当前您正在获取文章中的特色图片id。您是否正在尝试获取特色图片?