如何從數據庫中獲取精選圖片的網址?我將在前端顯示精選圖片。WordPress的:從數據庫中獲取精選圖片網址
0
A
回答
0
的特色圖像存儲在與meta_key的
wp_postmeta表_thumbnail_id
您可以通過
$Featured_image = $wpdb->get_results("
SELECT p.*
FROM net_5_postmeta AS pm
INNER JOIN net_5_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = $da_id
AND pm.meta_key = '_thumbnail_id'
ORDER BY p.post_date DESC
LIMIT 15
",'ARRAY_A'
或
SELECT * from {$wpdb->prefix}_posts
WHERE ID in (
SELECT meta_value FROM {$wpdb->prefix}_postmeta
WHERE meta_key = '_thumbnail_id'
AND post_id = ':ID'
);
得到它你的文章編號,取代ID
獲得那個職位縮略圖網址在WordPress
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>
供參考:URL
0
你可以試試這個代碼
if (have_posts()) : while (have_posts()) : the_post();
if (has_post_thumbnail()) {
$feat_image_url = wp_get_attachment_url(get_post_thumbnail_id());
// use the $feat_image_url variable as you like
}
endwhile;
endif;
希望這有助於
保重,快樂編碼
0
請嘗試這個
<?php $query = new WP_Query($args); ?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php if (has_post_thumbnail()): ?>
<a class="feature_image" href="<?php echo wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())); ?>">
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endif; ?>
相關問題
- 1. Echo Wordpress Post標題中的精選圖片網址
- 2. 獲取Wordpress附件圖片網址
- 3. 撤消刪除從數據庫中精選照片WordPress的
- 4. 如何從我的wordpress頁面獲取精選圖片描述?
- 5. 如何正確顯示WordPress的精選圖片網址?
- 6. 從內容中獲取圖片網址
- 7. 如何從帖子圖片網址設置精選圖片?
- 8. Rails:從數據庫獲取網址?
- 9. WordPress上的精選圖片
- 10. 從網址獲取數據
- 11. 從頁面獲取精選圖像網址
- 12. 從picasa獲取圖片直接網址
- 13. Laravel 4從網址獲取圖片
- 14. 使用AsyncTask從網址獲取圖片
- 15. 從網址獲取多個圖片
- 16. 從rss feed獲取圖片網址?
- 17. 從字符串獲取圖片網址
- 18. 從GMSPlace獲取圖片網址
- 19. 從Pinterest網址獲取所有圖片
- 20. WordPress wp_enqueue_media()break精選圖片
- 21. 如何在wordpress中獲取帖子的圖片網址?
- 22. 獲取WordPress的精選圖像「alt」
- 23. 從外部網址獲取圖片的網址
- 24. 如何檢索類別視圖中的精選圖片網址?
- 25. sql查詢:如何抓住wordpress中每個精選圖片的「文件網址」?
- 26. 如何在WordPress中獲取圖片網址?
- 27. 從帖子上的精選圖片加載wordpress頁腳圖片
- 28. 獲取數據從WordPress數據庫
- 29. 如何獲取與WordPress博客精選圖片相關的圖片文字?
- 30. 如何從flickr網址獲取靜態圖片網址?
注意get_post_thumbnail_id()需要$ POST_ID。希望這會幫助你。 –