2016-03-18 35 views
1

我想顯示一些帖子在錨標記中的內容並顯示爲鏈接,但我已經使用wp_trim_words函數我不知道如何允許html標記。我想在使用wp_trim_words時允許html標記

$more = ' <a href="'. get_permalink(get_the_ID()) . '" class="readMoreBtn">Read More</a>'; 
$content = wp_trim_words(get_the_content(), 50, $more); 
echo do_shortcode($content); 
+0

感謝它的工作。 – pia

+0

但通過the_content所有內容顯示我想顯示有限的內容。 – pia

+0

已添加新答案 –

回答

3

Aaaa我很笨。這將工作(測試):

$more = ' <a href="'. get_permalink(get_the_ID()) . '" class="readMoreBtn">Read More</a>'; 
echo force_balance_tags(html_entity_decode(wp_trim_words(htmlentities(get_the_content()), 50, $more))); 

我花了一段時間來記住,因此未顯示wp_trim_words()條從它的內容的所有標籤,你的HTML。所以我做了一點挖掘,發現這個寶石:

WordPress的軌道票#29533

希望這會有所幫助。對不起,以前的困惑:)

+0

not working.i想要允許html標記。 – pia

+0

我在內容中使用了播客播放器代碼,例如[smart_track_player url =「http://traffic.libsyn.com/abc/The_Seed_004__Hardwork_Pays_Off_With_Max_McGarity.mp3」title =「Hard WorkPhys With Max McGarity =」abc「image =」 https://www.jakeszaraz.com/wp-content/uploads/2016/02/TheSeedREALFinal.jpg「]請點擊這裏給我一個誠實的評級和評論在iTunes上,但是當我使用你的代碼的HTML標籤工作正常但我的播客代碼不能作爲播放器使用 – pia

+0

這是因爲此代碼輸出html原樣。我可以推薦使用[更多標籤](https://en.support.wordpress.com/more-tag/)'<-- more !-->' (wp_trim_words())會去掉html標籤,不適合摘錄,或者我建議你看看[優秀文章](http://wordpress.stackexchange.com/)。問題/ 141125/allow-html-in-excerpt/141136#141136)通過Pieter Goosen關於摘錄。 –

2

@dingo_d忘了添加wpautop()在代碼中。只需使用下面的代碼。

$more = ' <a href="'. get_permalink(get_the_ID()) . '" class="readMoreBtn">Read More</a>'; 

echo force_balance_tags(html_entity_decode(wp_trim_words(htmlentities(wpautop(get_the_content())), 100, $more))); 
相關問題