0
我沒有使用附件在wp中上傳圖像,
我使用外部主機如保管箱,如何通過特定的後置類型將其保存到我的首頁?如何在wp中獲取所有外部圖像
例如
<img src="https://www.dropbox.com/s/drgdrfhdtj.jpg?raw=1" alt="" width="506" height="673" />
<img src="https://www.dropbox.com/s/djtfdtjdtmjx.jpg?raw=1" alt="" width="506" height="714" />
如何得到這一切的形象呢?
我在function.php代碼
function gallery(){
$pid = get_the_ID();
$post = get_post($pid);
$content = $post->post_content;
$regex = '/src="([^"]*)"/';
preg_match_all($regex, $content, $matches);
foreach($matches as $image):
echo '<img src="'.$image.'" alt="'.$post->post_title.'" title="'.$post->post_title.'">' ;
endforeach;
}
我的內容gallery.php代碼
<?php $post_format = get_post_format(); ?>
<?php if ($post_format == 'gallery') : ?>
<div class="featured-media">
<?php gallery(); ?>
</div> <!-- /featured-media -->
<?php endif; ?>
但這不工作
編輯:
工作中使用的圖像[1](@Master djon回答)
現在的問題是
輸出:
<img src="https://www.dropbox.com/s/image1.jpg""><img https://www.dropbox.com/s/image1.jpg">
雙頭輸出一個圖像<img src=
和<img https://
如何解決這一問題?
這個輸出: – vallez
你的意思是:在'src = $ image'中使用'$ image'或者使用''src =「。 $ image [1]'?這給你'src =「數組」' –
哦是啊,工作,圖像只得到1,我有10圖像,如何顯示它全自動?沒有圖像[2],圖像[3] .... – vallez