0
我目前使用此代碼來獲得一個和下一個帖子鏈接和縮略圖如何獲取一篇文章首先圖片
<?php $prevPost = get_previous_post(true);
if($prevPost) {?>
<div class="nav-box previous" style="float:left;">
<?php $prevthumbnail = catch_that_image($prevPost->ID, array(100,100));}?>
<?php previous_post_link('%link',"$prevthumbnail %title", TRUE); ?>
</div>
<?php $nextPost = get_next_post(true);
if($nextPost) { ?>
<div class="nav-box next" style="float:right;">
<?php $nextthumbnail = catch_that_image($nextPost->ID, array(100,100)); } ?>
<?php next_post_link('%link',"$nextthumbnail %title", TRUE); ?>
</div>
但我想,而不是得到那個職位爲縮略圖的第一張圖像,特色圖片。
我發現這個代碼獲取當前帖子的第一張圖片,但是如何將它與上面的代碼一起使用來獲取上一篇文章或下一篇文章的第一張圖片?
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
return $first_img;
}