下面的代碼是很好的獲取信息網址和標題:如何獲取與WordPress博客精選圖片相關的圖片文字?
global $post;
$args = array('posts_per_page' => 5, 'offset'=> 1, 'category' => 4);
$myposts = get_posts($args);
foreach ($myposts as $post) : setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <br />
<?php
endforeach;
wp_reset_postdata();
但是我需要的是獲得功能圖像包括路徑的文/ url,但不是打印到屏幕上。這樣做的目的是讓我可以使用ImageMagick轉換創建自定義大小的圖像,並將其顯示到屏幕上而不是原始圖像。
我會做這樣的事情
convert "$image" -resized (my custom size) -strip 400x/$image
轉換代碼是更復雜一點,因爲我打算建立大型廣場豎起大拇指,但這是我們的目標。然後,我會將這些圖像發佈到一個頁面上的方形豎框畫廊以及各個帖子的鏈接中。
有沒有像the_featured_image()這樣的東西能讓我看到圖像,然後我可以將它設置爲一個變量並運行轉換代碼?
你的意思後縮略圖? the_post_thumbnail() –