WordPress Visual Composer无法在插入图像时获取和显示内容

问题描述 投票:2回答:1

我的函数中有一个自定义的vc_map,这是我的代码:

vc_map( array(
  'name' => __( 'myname Article Content', 'myname' ),
  'base' => 'myname-article-content', //my shortcode name
  'class' => '',
  'icon' => 'icon-wpb-vc_carousel',
  'category' => __( 'Content', 'myname' ),
  'description' => __( 'Content for Article', 'myname' ),
  'params' => array(
    array(
      'type' => 'textfield',
      'heading' => __( 'Image Caption', 'myname' ),
      'param_name' => 'caption',
      'description' => __( 'Enter text which will be used as Image    Caption.', 'myname' )
      ),
    array(
      'type' => 'textfield',
      'heading' => __( 'Image credits', 'myname' ),
      'param_name' => 'credits',
      'description' => __( 'Enter text which will be used as Image credits. Leave blank if no title is needed.', 'myname' )
      ),
    array(
      'type'        => 'textarea_html',
      'holder'      => 'div',
      'heading'     => __( 'Content', 'myname' ),
      'param_name'  => 'body_text',
      'description' => __( 'Enter the Body of the news', 'myname' )
      )
    )
  ) );

这是我的简短代码:

add_shortcode('myname-article-content','myname_article_content');

function myname_article_content($atts){

  $atts = shortcode_atts( array(
    'caption' =>'',
    'credits' => '',
    'body_text'=> ''
    ), $atts ); 

  extract($atts);

  $cat = get_the_category()
?>
<span class="category"><?php echo $cat[0]->name;?></span>
        <h2 class="popular-business"><?php the_title();?></h2>
        <div class="post-author"><strong>Published by:</strong> <?php the_author(); ?> <strong>Published Date</strong> <?php the_date(); ?></div>
        <?php
        if ( has_post_thumbnail() ):
        $feat_image_url = wp_get_attachment_url( get_post_thumbnail_id() ); 
        else:  
          $feat_image_url = MYTHEME_THEME_DIR_URI.'/assets/images/blank-img.png';
        endif;?>
        <div class="post-img" >
          <img src="<?php echo $feat_image_url ?>" alt="Image">
        </div>
        <p><?php echo $caption;?></p>
        <?php if($credits != '') {?>
        <p><strong>PHOTO BY</strong> <?php echo $credits;?></p>
        <?php } ?>
        <hr class="divider-full">
        <p><?php echo $body_text;?></p>
        <?php add_action('myname_text', $body_text); ?>
        <div class="gap gap-30"></div>
<p><strong>Share</strong></p>
<div class="gap gap-30"></div>

<?php
}

在这个代码..唯一不能正常工作的是我的视觉作曲家中的textarea_html。

如果内容没有添加图像,则vc_map在编辑器和前端中可操作。

但是当我添加一个图像时,在编辑器中保存内容后,textarea_html中的内容将显示在持有者中,它应该在哪里,但是当我再次单击编辑时,它无法获取textarea_html的内容但是显示其他内容,如文本字段。

另一件事,当我点击更新发布..如果没有添加图像,帖子在前端工作正常,但当我添加图像或任何媒体时,内容无法显示。

有任何想法吗?谢谢..

php wordpress wordpress-plugin
1个回答
1
投票

我在[Envato支持页面]上找到了帮助。(https://forums.envato.com/t/render-visual-composer-shortcodes-onto-page/126965

对于其他搜索,这是您如何回应Visual Composer中的textarea_html内容。如果textarea_html没有回应或你的textarea_html无效,请阅读此内容。

如果检查方法2,您将看到$content$atts一起作为参数传递。

在您的情况下,您需要将param_name更改为content

array(
    'type'        => 'textarea_html',
    'holder'      => 'div',
    'heading'     => __( 'Content', 'myname' ),
    'param_name'  => 'content',
    'description' => __( 'Enter the Body of the news', 'myname' )
)

...并传入$content变量:

function myname_article_content($atts, $content)

希望这有助于他人!

© www.soinside.com 2019 - 2024. All rights reserved.