我是wordpress插件開發的新手。我正在嘗試訪問發佈信息,並基於它是否具有精選圖像,我正在創建幻燈片。但圖片網址和帖子標題將從我的div標籤中刪除。以下是我的代碼。wordpress插件訪問帖子信息
//function to display post info
function postsinfo_collage_display($attr, $content) {
$plugins_url = plugins_url();
$html = '<div id="pscanvas" class="row">
<div class="row__inner mThumbnailScroller">';
// The Query
query_posts(array ('orderby' => 'date'));
// The Loop
while (have_posts()) : the_post();
if (has_post_thumbnail()) {
$html .= '<div class="tile">
<div class="tile__media">';
$html .='<a href="'.esc_url(get_permalink()).'">';
$html .='<img class="tile__img"';
$html .="src='".esc_url(the_post_thumbnail_url()). "'/>";
$html .='</a></div><div class="tile__details">
<div class="tile__title">';
$html .= the_title();
$html .='</div></div></div>';
}
endwhile;
// Reset Query
wp_reset_query();
$html .= '</div>
</div>
<script>
window.jQuery || document.write(\'<script src="minified/jquery-1.11.0.min.js"><\/script>\')
(function($){
$(window).load(function(){
});
})(jQuery);</script>';
return $html;
}
我得到的輸出是:
<div class="entry-content">
http://localhost:9085/wordpress/wp-content/uploads/2016/04/call-of-duty-ghosts-20517-1366x768-1200x675.jpgpscanvashttp://localhost:9085/wordpress/wp-content/uploads/2016/04/Call-Of-Duty-Ghost-Background-For-Wallpaper-652-1200x675.jpgkwofkwc
<div id="pscanvas" class="row">
<div class="row__inner mThumbnailScroller ">
<div id="mTS_1" class="mTSWrapper mTS_horizontal">
<div class="mTSAutoContainer mTSContainer" ">
<div class="tile">
<div class="tile__media">
<a href="http://localhost:9085/wordpress/2016/09/04/pscanvas/">
<img class="tile__img" src=""></a>
</div><div class="tile__details">
<div class="tile__title"></div></div></div>
<div class="tile"><div class="tile__media">
<a href="http://localhost:9085/wordpress/2016/05/03/kwofkwc/">
<img class="tile__img" src=""></a></div><div class="tile__details">
<div class="tile__title"></div></div></div>
</div>
</div>
</div>
</div>
<script>
window.jQuery || document.write('<script src="minified/jquery-1.11.0.min.js"><\/script>')
(function($){
$(window).load(function(){
});
})(jQuery);</script>
<strong>Album Rating:</strong> <div class="genericon genericon-star"></div><br> </div>
我可以看到圖像的URL應該是img標籤,但其現身整個div標籤內。
用途:https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/ – huhu
我試過,以及在開始。但同樣的產出。我不明白爲什麼網址會出現在我的主pscanvas div標記中。如果我使用回聲get_permalink(),同樣工作正常。 – Madie
謝謝。更改爲:$ imgurl = wp_get_attachment_url(get_post_thumbnail_id()); $ posturl = get_permalink(); $ title = the_title(); \t $ html。='