短代码呈现为文本而不是短代码应该 [英] Shortcode rendering as text not as shortcode should

查看:28
本文介绍了短代码呈现为文本而不是短代码应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个购物网站,我正在尝试在其中添加一个短代码,该短代码将向客户显示购买按钮以及客户想要购买的产品数量.在我的帖子页面上,短代码工作正常:

http://warringah-plastics.com.au/blog/dt_catalog/recess-gasket-large/

但在存档页面上:

http://warringah-plastics.com.au/store/

显示为文本的短代码 ID,而不是实际的按钮和数量,例如[add_to_cart item="FPROWAR-160713-1" showprice="no"quantity="user:1" ajax="yes" ].

在帖子页面中工作的代码是这样的:

但它只是在该存档页面上显示短代码文本.谁有想法?非常感谢,

<小时>

更新

这是正确显示短代码的代码:

<?php dt_storage('have_sidebar', true);?><?php get_template_part('top-bg');?><?php get_template_part('视差');?><div id="包装器"><?php get_template_part('nav');?><div id="容器"><?php if( have_posts() ): while( have_posts() ): the_post();?><h1><?php the_title();?></h1><h1 style="color: #3C3C3B !important; margin-top:-20px !important;"><?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'dt_catalog_category', '', ', ', '' ) );回声 $terms_as_text;?></h1><?php全球 $post;$post_opts = get_post_meta($post->ID, '_dt_catalog-post_options', true);if(!isset($post_opts['hide_media']) || (isset($post_opts['hide_media']) && !$post_opts['hide_media']) ) {$args = 数组('post_type' =>'依恋','post_status' =>'继承','posts_per_page' =>-1,'post_parent' =>$post->ID,'post_mime_type' =>'图片','orderby' =>'menu_order','订单' =>'ASC');if(!empty($post_opts['hide_thumbnail']))$args['post__not_in'] = array( get_post_thumbnail_id() );$dt_tmp_query = new WP_Query( $args);if( $dt_tmp_query->have_posts() ) {$slides = array();foreach( $dt_tmp_query->posts as $slide ) {$video = get_post_meta( $slide->ID, '_dt_catalog_video_link', true );$tmp_arr = array();$tmp_arr['caption'] = $slide->post_excerpt;如果(!$视频){$slide_src = dt_get_resized_img( wp_get_attachment_image_src( $slide->ID, 'full' ), array( 'w' => 710 ) );$tmp_arr['alt'] = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );$tmp_arr['src'] = $slide_src[0];$tmp_arr['size_str'] = $slide_src[3];} 别的 {$tmp_arr['is_video'] = true;$tmp_arr['src'] = $video;$tmp_arr['size_str'] = array(710, 1024);}$slides[] = $tmp_arr;}dt_get_anything_slider( array( 'id' => 'slider2', 'items_arr' => $slides ) );}}?><?php $opts = get_post_meta($post->ID, '_dt_catalog-goods_options', true);?><?php if(!empty($opts['price'])): ?><span class="price"><?php _e('Price: ', LANGUAGE_ZONE);echo esc_html($opts['price']);?></span><?php endif;?><?php$my_textbox_value = mtbxr_val("shopping_shortcode");echo do_shortcode("$my_textbox_value");?><?php内容();如果(dt_is_page_soc_buttons_enabled('目录')){dt_get_like_buttons(get_the_ID());}?><?php if(!empty($opts['p_link'])): ?><a href="<?php echo esc_url($opts['p_link']); ?>"class="button" title=""><span><i class="dol"></i><?php _e('购买!', LANGUAGE_ZONE);?></span></a><?php endif;?><p class="gap"></p><?php$rel_works = get_post_meta($post->ID, '_dt_catalog_related', true);if( isset($rel_works['show_related']) && $rel_works['show_related'] ):if('same' == $rel_works['related'] ) {$rel_works['related'] = wp_get_post_terms($post->ID,'dt_catalog_category',数组('字段' => 'ids'));}if( !empty($rel_works['related']) ):?><p class="hr hr-narrow gap-small"></p><div class="gap"></div><div class="全宽 w-photo"><h2><?php _e('相关项目', LANGUAGE_ZONE);?></h2><?phpif('same' == $rel_works['related'] ) {$rel_works['related'] = wp_get_post_terms($post->ID,'dt_catalog_category',数组('字段' => 'ids'));}$dt_tmp_query = new WP_Query( 数组('posts_per_page' =>-1,'post_type' =>'dt_catalog','post_status' =>'发布','post__not_in' =>数组($post->ID),'tax_query' =>数组(数组('分类' =>'dt_catalog_category','字段' =>'ID','条款' =>$rel_works['相关'],'运算符' =>'在') )) );if( $dt_tmp_query->have_posts() ) {$thumb_arr = dt_core_get_posts_thumbnails( $dt_tmp_query->posts );$items = array();foreach( $dt_tmp_query->posts as $rel_post ) {$item = 数组();$img = dt_get_resized_img(dt_get_thumb_meta($thumb_arr['thumbs_meta'], 'full', $rel_post->ID),数组('w' => 196,'h' => 123,'use_noimage' => true));$item['src'] = $img[0];$item['size_str'] = $img[2];$item['post_id'] = $rel_post->ID;$item['desc'] = apply_filters('get_the_excerpt', $rel_post->post_excerpt);$item['title'] = apply_filters('the_title', $rel_post->post_title, $rel_post->ID);$item['alt'] = esc_attr( $item['title'] );$items[] = $item;}$args = array( 'items_arr' => $items, 'id' => '', 'class' => 'list-carousel 最近的 bx', 'ul_class' => 'slider1' );$args['wrap'] = '<div class="%CLASS% bx">%SLIDER%</div>';if( !empty( $rel_works['show_desc'] ) || !empty( $rel_works['show_title'] ) ) {$title = '';如果(!空($rel_works['show_title'])){$title = '<h3><a href="%LINK%" class="head">%TITLE%</a></h3>';}$desc = '';如果(!空($rel_works['show_desc'])){$desc = '

%DESC%

';}$args['item_wrap'] = '<li><div class="textwidget"><div class="textwidget-photo"><a class="photo" href="%LINK%"><img src="%IMG_SRC%" alt="%ALT%" %IMG_SIZE%/></a>

<div class="widget-info"><div class="信息">' .$title .$desc .'

';}dt_get_carousel_slider($args);}?>

<?php endif;万一;?><?php comments_template();?><?php终了;万一;?>

<?php dt_widget_area('sidebar', null, 'sidebar_4');?>

<?php get_footer();?>

这是将短代码显示为文本的代码:

ID, '_dt_catalog-goods_options', true);?><div class="<?php dt_portfolio_classes('2_col-list', 'block'); echo $first_class; ?>"><?php$h = 220;如果(!空($page_opts['thumb_height'])){$h = $page_opts['thumb_height'];}dt_get_thumb_img( 数组('类' =>'照片','use_noimage' =>真的,'href' =>get_permalink(),'thumb_opts' =>数组('w' => 343,'h' => $h)),'<div class="textwidget-photo"><a %HREF% %CLASS% %TITLE% %CUSTOM%><img %ALT% %SRC% %IMG_CLASS% %SIZE%/></a>

');?><div class="<?php dt_portfolio_classes('2_col-list', 'info'); ?>"><a class="<?php dt_portfolio_classes('2_col-list', 'head'); ?>"href="<?php the_permalink(); ?>"><?php the_title();?></a><?php if(!empty($opts['price'])): ?><span class="price"><?php _e('Price: ', LANGUAGE_ZONE);echo esc_html($opts['price']);?></span><?php endif;?><?phpdt_the_content();dt_details_link();dt_edit_link();?><div id="specialpriceshortcode"><?php$my_textbox_value = mtbxr_val("shopping_shortcode");echo do_shortcode("$my_textbox_value");?>

解决方案

尝试在 do_shortcode 调用中使用单引号,如下所示:

 echo do_shortcode('$my_textbox_value');

但更有可能的是,短代码未在存档页面上定义,因此您需要查看它的实例化位置以查看是否存在问题.通常,当短代码只是回显内容时,这意味着短代码不存在.您可以使用 shortcode_exists() 函数轻松进行测试:

<?php if ( shortcode_exists( 'add_to_cart' ) ) { echo "The shortcode exists";} ?>

如果这不起作用,那么您知道问题在于短代码未在您的档案页面上注册.如果它确实有效,那么您就会知道它与传递给短代码的内容格式有关.

I am building a shopping website and I am trying to put a shortcode in that will show the customer a buy button and the quantity of the product the customer wants to purchase. On my post page the shortcode works fine:

http://warringah-plastics.com.au/blog/dt_catalog/recess-gasket-large/

but on the archive page:

http://warringah-plastics.com.au/store/

the shortcode id displayed as text and not the actual button and quantity e.g. [add_to_cart item="FPROWAR-160713-1" showprice="no" quantity="user:1" ajax="yes" ].

The code that works in the post page is this:

<?php 
$my_textbox_value = mtbxr_val("shopping_shortcode");
echo do_shortcode("$my_textbox_value"); 
?>

but it just displays the shortcode text on that archive page. Anyone have any ideas? Much appreciated,


UPDATE

THIS IS THE CODE THAT DISPLAYS THE SHORTCODE CORRECTLY:

<?php get_header(); ?>
<?php dt_storage('have_sidebar', true); ?>

    <?php get_template_part('top-bg'); ?>

    <?php get_template_part('parallax'); ?>

    <div id="wrapper">

        <?php get_template_part('nav'); ?>

        <div id="container">

            <?php if( have_posts() ): while( have_posts() ): the_post(); ?>

                <h1><?php the_title(); ?></h1>



<h1 style="color: #3C3C3B !important; margin-top:-20px !important;"><?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'dt_catalog_category', '', ', ', '' ) );
echo $terms_as_text; ?></h1>


            <?php
            global $post;
            $post_opts = get_post_meta($post->ID, '_dt_catalog-post_options', true);

            if( !isset($post_opts['hide_media']) || (isset($post_opts['hide_media']) && !$post_opts['hide_media']) ) {
                $args = array(
                    'post_type'         => 'attachment',
                    'post_status'       => 'inherit',
                    'posts_per_page'    => -1,
                    'post_parent'       => $post->ID,
                    'post_mime_type'    => 'image',
                    'orderby'           => 'menu_order',
                    'order'             => 'ASC'
                );
                if( !empty($post_opts['hide_thumbnail']) )
                    $args['post__not_in'] = array( get_post_thumbnail_id() );

                $dt_tmp_query = new WP_Query( $args );
                if( $dt_tmp_query->have_posts() ) {
                    $slides = array();
                    foreach( $dt_tmp_query->posts as $slide ) {
                        $video = get_post_meta( $slide->ID, '_dt_catalog_video_link', true );
                        $tmp_arr = array();

                        $tmp_arr['caption'] = $slide->post_excerpt;
                        if ( ! $video ) {
                            $slide_src = dt_get_resized_img( wp_get_attachment_image_src( $slide->ID, 'full' ), array( 'w' => 710 ) );
                            $tmp_arr['alt'] = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
                            $tmp_arr['src'] = $slide_src[0];
                            $tmp_arr['size_str'] = $slide_src[3];
                        } else {
                            $tmp_arr['is_video'] = true; 
                            $tmp_arr['src'] = $video; 
                            $tmp_arr['size_str'] = array( 710, 1024 );
                        }
                        $slides[] = $tmp_arr;
                    }
                    dt_get_anything_slider( array( 'id' => 'slider2', 'items_arr' => $slides ) );
                }
            }
            ?>

                <?php $opts = get_post_meta($post->ID, '_dt_catalog-goods_options', true); ?>

                <?php if( !empty($opts['price']) ): ?>

                <span class="price"><?php _e('Price: ', LANGUAGE_ZONE); echo esc_html($opts['price']); ?></span>

                <?php endif; ?>





                        <?php 
                $my_textbox_value = mtbxr_val("shopping_shortcode");

                echo do_shortcode("$my_textbox_value"); 

                ?>



                <?php
                the_content();

                if( dt_is_page_soc_buttons_enabled('catalog') ) {
                    dt_get_like_buttons( get_the_ID() );
                }
                ?>

                <?php if( !empty($opts['p_link']) ): ?>

                    <a href="<?php echo esc_url($opts['p_link']); ?>" class="button" title=""><span><i class="dol"></i><?php _e('Make purchase!', LANGUAGE_ZONE); ?></span></a>

                <?php endif; ?>

                <p class="gap"></p>
                <?php
                $rel_works = get_post_meta($post->ID, '_dt_catalog_related', true);
                if( isset($rel_works['show_related']) && $rel_works['show_related'] ):
                    if( 'same' == $rel_works['related'] ) {
                        $rel_works['related'] = wp_get_post_terms(
                            $post->ID,
                            'dt_catalog_category',
                            array('fields' => 'ids')
                        );
                    }
                    if( !empty($rel_works['related']) ):
                ?>

                <p class="hr hr-narrow gap-small"></p>

                <div class="gap"></div>
                <div class="full-width w-photo">
                    <h2><?php _e('Related Items', LANGUAGE_ZONE); ?></h2>

                    <?php
                    if( 'same' == $rel_works['related'] ) {
                        $rel_works['related'] = wp_get_post_terms(
                            $post->ID,
                            'dt_catalog_category',
                            array('fields' => 'ids')
                        );
                    }
                    $dt_tmp_query = new WP_Query( array(
                        'posts_per_page'    => -1,
                        'post_type'         => 'dt_catalog',
                        'post_status'       => 'publish',
                        'post__not_in'      => array($post->ID),
                        'tax_query'         => array( array(
                            'taxonomy'  => 'dt_catalog_category',
                            'field'     => 'id',
                            'terms'     =>  $rel_works['related'],
                            'operator'  => 'IN'
                        ) )    
                    ) );
                    if( $dt_tmp_query->have_posts() ) {
                        $thumb_arr = dt_core_get_posts_thumbnails( $dt_tmp_query->posts );
                        $items = array();
                        foreach( $dt_tmp_query->posts as $rel_post ) {
                            $item = array();
                            $img = dt_get_resized_img(
                                dt_get_thumb_meta($thumb_arr['thumbs_meta'], 'full', $rel_post->ID),
                                array('w' => 196, 'h' => 123, 'use_noimage' => true)
                            );
                            $item['src'] = $img[0];
                            $item['size_str'] = $img[2];
                            $item['post_id'] = $rel_post->ID;

                            $item['desc'] = apply_filters('get_the_excerpt', $rel_post->post_excerpt);
                            $item['title'] = apply_filters('the_title', $rel_post->post_title, $rel_post->ID);
                            $item['alt'] = esc_attr( $item['title'] );

                            $items[] = $item;
                        }

                        $args = array( 'items_arr' => $items, 'id' => '', 'class' => 'list-carousel recent bx', 'ul_class' => 'slider1' );
                        $args['wrap'] = '<div class="%CLASS% bx">%SLIDER%</div>';

                        if( ! empty( $rel_works['show_desc'] ) || ! empty( $rel_works['show_title'] ) ) {

                            $title = '';
                            if( ! empty( $rel_works['show_title'] ) ) {
                                $title = '<h3><a href="%LINK%" class="head">%TITLE%</a></h3>';
                            }

                            $desc = '';
                            if( ! empty( $rel_works['show_desc'] ) ) {
                                $desc = '<p>%DESC%</p>';
                            }

                            $args['item_wrap'] = '
                            <li>
                                <div class="textwidget">
                                    <div class="textwidget-photo">
                                        <a class="photo" href="%LINK%"><img src="%IMG_SRC%" alt="%ALT%" %IMG_SIZE% /></a>
                                    </div>
                                    <div class="widget-info">
                                        <div class="info">
                                            ' . $title . $desc . '
                                        </div>
                                </div>
                                </div>
                            </li>
                            ';

                        }
                        dt_get_carousel_slider( $args );
                    }
                    ?>






                </div>

                <?php endif; endif; ?>

                <?php comments_template(); ?>

            <?php
                endwhile;
            endif;
            ?>

        </div>







<?php dt_widget_area('sidebar', null, 'sidebar_4'); ?>



    </div>

<?php get_footer(); ?>

AND THIS IS THE CODE THAT DISPLAYS THE SHORTCODE JUST AS TEXT:

<?php
global $post;
$page_data = dt_storage( 'page_data' );
$page_opts = ! empty( $page_data['page_options'] ) ? $page_data['page_options'] : array();
$add_data = dt_storage( 'add_data' );

$first_class = '';
if( 1 === dt_storage('post_is_first') ) {
    $first_class = ' first';
    dt_storage( 'post_is_first', -1 );
}

$opts = get_post_meta($post->ID, '_dt_catalog-goods_options', true);
?>
<div class="<?php dt_portfolio_classes( '2_col-list', 'block' ); echo $first_class; ?>">

        <?php
        $h = 220;
        if ( ! empty ( $page_opts['thumb_height'] ) ) {
            $h = $page_opts['thumb_height'];
        }
        dt_get_thumb_img( array(
            'class'         => 'photo',
            'use_noimage'   => true,
            'href'          => get_permalink(),
            'thumb_opts'    => array( 'w' => 343, 'h' => $h )
            ),
            '<div class="textwidget-photo">
                <a %HREF% %CLASS% %TITLE% %CUSTOM%><img %ALT% %SRC% %IMG_CLASS% %SIZE% /></a>
            </div>'
        );
        ?>

    <div class="<?php dt_portfolio_classes( '2_col-list', 'info' ); ?>">
        <a class="<?php dt_portfolio_classes( '2_col-list', 'head' ); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

        <?php if( !empty($opts['price']) ): ?>

        <span class="price"><?php _e('Price: ', LANGUAGE_ZONE); echo esc_html($opts['price']); ?></span>




        <?php endif; ?>

        <?php
        dt_the_content();
        dt_details_link();
        dt_edit_link();

        ?>



        <div id="specialpriceshortcode">

        <?php 
                $my_textbox_value = mtbxr_val("shopping_shortcode");

                echo do_shortcode("$my_textbox_value"); 

                ?>




    </div>  

    </div>



</div>

解决方案

Try using single quotes in the do_shortcode call, like so:

 echo do_shortcode('$my_textbox_value');

More likely though is that the shortcode isn't defined on the archive page so you'd need to look at where it is being instantiated to see if that is the issue. Normally when a shortcode just echoes out the content it means that shortcode doesn't exist. You can test easily enough by using the shortcode_exists() function:

<?php if ( shortcode_exists( 'add_to_cart' ) ) { echo "The shortcode exists";} ?> 

If that doesn't work then you know the issue is with the shortcode not being registered on your archives page. If it does work then you know it's something with the format of the content being passed to the shortcode.

这篇关于短代码呈现为文本而不是短代码应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆