Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的[shortcodes]在WP编辑器中显示为纯文本?_Php_Wordpress - Fatal编程技术网

Php 为什么我的[shortcodes]在WP编辑器中显示为纯文本?

Php 为什么我的[shortcodes]在WP编辑器中显示为纯文本?,php,wordpress,Php,Wordpress,我正在尝试使用短代码在我的网站的不同页面上执行特定于标签的内容循环。我知道我的shortcode函数工作正常,因为当我将do\u shortcode硬编码到我的页面模板中时,它会完美地显示出来 但是当我尝试直接将[shortcode]添加到Wordpress编辑器中时,它显示为纯文本。有没有办法解决这个问题 您可以看到我在说什么-您看到的纯文本直接写入Wordpress文本编辑器中。它不能正常工作。就在它的下方,您将看到看到我正在开发的插件中的代码,这是很久以前的事了,但是您可以看到“do_sh

我正在尝试使用短代码在我的网站的不同页面上执行特定于标签的内容循环。我知道我的shortcode函数工作正常,因为当我将
do\u shortcode
硬编码到我的页面模板中时,它会完美地显示出来

但是当我尝试直接将
[shortcode]
添加到Wordpress编辑器中时,它显示为纯文本。有没有办法解决这个问题


您可以看到我在说什么-您看到的纯文本直接写入Wordpress文本编辑器中。它不能正常工作。就在它的下方,您将看到
看到我正在开发的插件中的代码,这是很久以前的事了,但是您可以看到“do_shortcode()”函数包含在内,请尝试将其添加到$output中

function rir_row( $params, $content = null ) {
    extract( shortcode_atts( array(
        'class' => 'rir-row'
    ), $params ) );
    $content = preg_replace( '/<br class="nc".\/>/', '', $content );
    $result = '<div class="' . $class . '">';
    $result .= do_shortcode( $content );
    $result .= '</div>';
    return force_balance_tags( $result );
}
add_shortcode('rir_row', 'rir_row');

function rir_item( $params, $content=null ) {
    extract( shortcode_atts( array(
        'class' => 'col-sm-1'
        ), $params ) );

    $result = '<div class="' . $class . '">';
    $result .= do_shortcode( $content );
    $result .= '</div>';
    return force_balance_tags( $result );
}
add_shortcode( 'rir_item', 'rir_item' );
函数rir\u行($params,$content=null){
提取(短码)附件(数组)(
“类”=>“里尔行”
),$params));
$content=preg_replace('/
/',''$content); $result=''; $result.=do_短代码($content); $result.=''; 返回力\平衡\标签($result); } 添加_短代码('rir_行'、'rir_行'); 函数rir_项($params,$content=null){ 提取(短码)附件(数组)( “类”=>“列-sm-1” ),$params)); $result=''; $result.=do_短代码($content); $result.=''; 返回力\平衡\标签($result); } 添加快捷码(“rir_项”、“rir_项”);
查看我正在开发的插件中的代码,这是很久以前的事了,但是您可以看到包含了“do_shortcode()”函数,请尝试将其添加到$output中

function rir_row( $params, $content = null ) {
    extract( shortcode_atts( array(
        'class' => 'rir-row'
    ), $params ) );
    $content = preg_replace( '/<br class="nc".\/>/', '', $content );
    $result = '<div class="' . $class . '">';
    $result .= do_shortcode( $content );
    $result .= '</div>';
    return force_balance_tags( $result );
}
add_shortcode('rir_row', 'rir_row');

function rir_item( $params, $content=null ) {
    extract( shortcode_atts( array(
        'class' => 'col-sm-1'
        ), $params ) );

    $result = '<div class="' . $class . '">';
    $result .= do_shortcode( $content );
    $result .= '</div>';
    return force_balance_tags( $result );
}
add_shortcode( 'rir_item', 'rir_item' );
函数rir\u行($params,$content=null){
提取(短码)附件(数组)(
“类”=>“里尔行”
),$params));
$content=preg_replace('/
/',''$content); $result=''; $result.=do_短代码($content); $result.=''; 返回力\平衡\标签($result); } 添加_短代码('rir_行'、'rir_行'); 函数rir_项($params,$content=null){ 提取(短码)附件(数组)( “类”=>“列-sm-1” ),$params)); $result=''; $result.=do_短代码($content); $result.=''; 返回力\平衡\标签($result); } 添加快捷码(“rir_项”、“rir_项”);
您的主题似乎没有对帖子的内容执行dou shortcode()

尝试将以下内容添加到functions.php

function the_content_filter( $content) {
    return do_shortcode( $content);
}

add_filter( 'the_content', 'the_content_filter', 1000);
更新

从主题的代码中,我们可以看到您使用get_post_字段来输出文章的内容。与_content()不同,此函数不调用任何筛选器。这就是上面的代码在您的案例中不起作用的原因

必须按以下方式使用get_post_field():

<?php echo do_shortcode( get_post_field( 'post_content', $post->ID ) ); ?>


另外,你也应该避免使用,因为你的主题似乎没有对文章的内容执行dou shortcode()

尝试将以下内容添加到functions.php

function the_content_filter( $content) {
    return do_shortcode( $content);
}

add_filter( 'the_content', 'the_content_filter', 1000);
更新

从主题的代码中,我们可以看到您使用get_post_字段来输出文章的内容。与_content()不同,此函数不调用任何筛选器。这就是上面的代码在您的案例中不起作用的原因

必须按以下方式使用get_post_field():

<?php echo do_shortcode( get_post_field( 'post_content', $post->ID ) ); ?>


另外,你也应该避免使用“谢谢你关注我”这个词。我不想在你解决了原来的问题后就把原来的问题拖下水,因此在这一页上有了新的问题。我已经将您的新代码添加到functions.php中,但不幸的是没有运气。我衷心感谢您继续帮助像我这样的新手-还有其他想法吗?您能在输出页面的主题中显示模板的php代码吗?如何输出页面内容?没问题-请参见上文。我在问题结束前添加了它。我强烈建议应用
do\u shortcode
过滤器,而不是
do\u shortcode
过滤器:
apply\u过滤器('the\u content',$post->post\u content)
。之所以提出此建议,是因为默认的
过滤器调用
autoembed
wp\u-texturize
convert\u-smiles
wp-autop
shortcode\u-top
prepend\u-attachment
wp\u-make\u-content\u-images\u-responsible
dou-shortcode>过滤器,WordPress-post的正常处理顺序是什么。谢谢您关注我。我不想在你解决了原来的问题后就把原来的问题拖下水,因此在这一页上有了新的问题。我已经将您的新代码添加到functions.php中,但不幸的是没有运气。我衷心感谢您继续帮助像我这样的新手-还有其他想法吗?您能在输出页面的主题中显示模板的php代码吗?如何输出页面内容?没问题-请参见上文。我在问题结束前添加了它。我强烈建议应用
do\u shortcode
过滤器,而不是
do\u shortcode
过滤器:
apply\u过滤器('the\u content',$post->post\u content)
。之所以提出此建议,是因为默认的
过滤器调用
autoembed
wp\u纹理化
convert\u smiles
wpsotop
shortcode\u-top
prepend\u-attachment
wp\u-make\u-content\u-images\u-responsible
dou-shortcode>过滤器,WordPress-post的正常处理顺序是什么。