(Wordpress)我怎么能得到一个帖子的全部内容与html标签-未剥离


(Wordpress) How can i get the full content of a post with the html tags - unstripped

我使用WordPress为我的网站与qtranslate插件,我试图在每个帖子中显示语言标志。

Qtranslate在内容和标题中插入html标记"!——:en ->"对于我在每篇文章中使用的每种语言

所以我需要一个条件来检查哪些html标签包含在内容中,这样我就可以打印特定的标志

像这样:

function language_pick(){
    $qt_dir = "http://localhost/MY-SITE/wp-content/plugins/qtranslate-xp/flags/";
    $cr_url = "http://".$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    $en_url = esc_html($cr_url."&lang=en");
    $fr_url = esc_html($cr_url."&lang=fr");
    $it_url = esc_html($cr_url."&lang=it");
    $es_url = esc_html($cr_url."&lang=es");
    $query = get_post(get_the_ID()); 
    $content = apply_filters('the_content', $query->post_content);
    if(get_permalink() != $cr_url) { echo '<a style="margin-left:15px;" href="'.$cr_url.'" /><img src="'.$qt_dir.'gr.png"></a>'; }
    if (strpos($content, '<!--:en-->') === true) {
         if(get_permalink() != $en_url) { echo '<a style="margin-left:15px;" href="'.$en_url.'" /><img src="'.$qt_dir.'gb.png"></a>'; } }
    if(strpos($content,'<!--:fr-->') === true) {
        if(get_permalink() != $fr_url) { echo '<a style="margin-left:15px;" href="'.$fr_url.'" /><img src="'.$qt_dir.'fr.png"></a>'; } }
    if(strpos($content,'<!--:it-->') === true) {
        if(get_permalink() != $it_url) { echo '<a style="margin-left:15px;" href="'.$it_url.'" /><img src="'.$qt_dir.'it.png"></a>'; } }
    if(strpos($content,'<!--:es-->') === true) {
        if(get_permalink() != $es_url) { echo '<a style="margin-left:15px;" href="'.$es_url.'" /><img src="'.$qt_dir.'es.png"></a>'; } }
}

非常简单地添加<?= apply_filters('the_content', $content); ?>

谷歌上有很多关于这个的参考资料。

编辑在这个例子中:

$query = get_post(get_the_ID()); 
$content = apply_filters('the_content', $query->post_content);
echo $content;

这有助于在单个帖子模板中呈现HTML标签,就像您在编辑器中看到的那样/

$content = apply_filters('the_content', get_the_content());
echo $content ;