[英]WordPress the_content() does not show images (if not other content surrounding)
我為WordPress(4.4.2)構建了自定義主題。 我使用標准的內置編輯器來創建帖子。 如果我創建帶有標題,段落和圖片的帖子,則會顯示內容(圖片也是如此)。 但是,如果僅輸入標題,並在編輯器的內容區域中輸入圖像,則該圖像將不再顯示文字,該圖像將不會顯示在網站上。
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="container-fluid site-content content-area" role="main">
<div class="container">
<?php if (!empty_content($post->post_content)) :?>
<div class="content row col-md-10 xcentered">
<?php the_content(); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endwhile; endif; ?>
我也嘗試了沒有if語句的代碼,但是the_content()不會顯示沒有任何其他內容的圖像。
除了div.container之外的所有東西都被渲染。 並且,只要在圖像標題之前/之后添加一個字符,就會渲染字符和圖像。
有什么建議我需要在其他地方進行更改嗎? 為什么圖像無法識別為“獨立”?
您正在使用的函數“ empty_content”,已在您的問題注釋中提供:
function empty_content($str) {
return trim(str_replace(' ','',strip_tags($str))) == '';
}
當我將<img src="someimg.png">
放入此函數時,它返回true,表示未渲染<div>
。
這正是您所描述的行為。
嘗試http://phpfiddle.org/以下代碼:
function empty_content($str) {
return trim(str_replace(' ','',strip_tags($str))) == '';
}
$only_img = '<img src="someimg.png">';
$img_and_more = '<img src="someimg.png"><p>Some other stuff</p>';
var_dump(empty_content($only_img));
var_dump(empty_content($img_and_more));
您將看到$only_img
變量轉儲到true
和$img_and_more
轉儲為false。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.