[英]WordPress Visual Composer Unable to fetch and show the content when image is inserted
我的函数中有一个自定义的 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 的内容但是显示文本字段等其他内容。
另一件事,当我点击更新帖子时..如果没有添加图片,帖子在前端工作正常,但是当我添加图片或任何媒体时,内容无法显示。
有任何想法吗? 谢谢..
我在这个 [Envato 支持页面] 上找到了帮助。( https://forums.envato.com/t/render-visual-composer-shortcodes-onto-page/126965 )
对于其他搜索,这就是您从 Visual Composer 回显textarea_html
内容的方式。 如果textarea_html
没有回显或您的textarea_htm
不起作用,请阅读此内容。
如果您检查方法 2,您将看到$content
作为参数与$atts
一起$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)
希望这对其他人有帮助!
这是对我有用的代码,
param_name
应该是内容。$content
和$atts
。shortcode_atts
定义内容。下面是一个例子:
public function render_html( $atts , $content) {
// Params extraction
extract(
shortcode_atts(
array(
'image' => '',
'title' => '',
'button_text' => '',
'button_url' => '',
),
$atts
)
);
$html = '';
$html = include('templates/render-html.php'); // this will include my page html
return $html;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.