(WordPress的)我怎样才能得到一个职位的HTML标签的全部内容 - 未剥离 [英] (Wordpress) How can i get the full content of a post with the html tags - unstripped

查看:126
本文介绍了(WordPress的)我怎样才能得到一个职位的HTML标签的全部内容 - 未剥离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用qtranslate插件将WordPress用于我的网站,并且我试图在每篇文章中显示语言标记。

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'< ; 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>'; }} $ b $ 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>'; }}


解决方案

code><?= apply_filters('the_content',$ content); ?>



在Google上有很多这方面的参考资料。

编辑
所以在这种情况下:

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

echo $ content;


I'm using WordPress for my site with the qtranslate plugin and i'm trying to display language flags in each post.

Qtranslate inserts html tags to the content and title like "!--:en-->" for each language that i used in each post

So i need a conditional that checks which of these html tags are included in the content so i can print the specific flags

something like this:

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>'; } }
}

解决方案

Very simply add <?= apply_filters('the_content', $content); ?>

There are loads of references to this on Google.

EDIT So in this case:

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

echo $content;

这篇关于(WordPress的)我怎样才能得到一个职位的HTML标签的全部内容 - 未剥离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆