0

我在 VC 中设置了一个自定义元素,供用户添加一个带有自定义文本、链接和(自定义)字体图标的按钮。

我可以回显标题和链接,但字体图标是空白的。当我 print_r($atts) 我得到这个:

Array
(
    [reach_vc_button_text] => More Information
    [reach_vc_button_link] => url:http%3A%2F%2Flocalhost%2FWordPress%2FJammyCustard%2Freach%2Ffunding%2Fthriving-rural-communities-scheme-trc%2F|||
    [reach_vc_button_icon] => 
);

    <?php
function reach_vc_button_html( $atts ) {

    $atts = shortcode_atts(
        array(
            'reach_vc_button_text' => '',
            'reach_vc_button_link' => '',
            'reach_vc_button_icon' => '',
        ), $atts, 'reach_vc_button'
    );

    ob_start();
    ?>

        <?php
            $href = $atts['reach_vc_button_link'];
            $button_link = vc_build_link( $href );

            //echo '<pre>'; print_r($atts); echo '</pre>';

        ?>  

    <a href="<?php echo $button_link['url']; ?>" class="read-more excerpt-read-more project-read-more"><?php echo $atts['reach_vc_button_text']; ?><i class="<?php echo $atts['reach_vc_button_icon']; ?>"></i></a>

    <?php
    $html = ob_get_clean(); 
    return $html;

}

add_shortcode( 'reach_vc_button', 'reach_vc_button_html' );

编辑:添加参数代码:

array(
                "type"        => "iconpicker",
                "heading"     => __( "Button Icon", "reach-rdp" ),
                "param_name"  => "reach_vc_button_icon",
                "value"       => "icon-more-information",
                "description" => __( "Select the icon to display for this button", "reach-rdp" ),
                "settings"   => array(
                    "emptyIcon"    => false,
                    "type"         => "reach",
                    "iconsPerPage" => "50",
                ),
                "dependency" => array(
                    "element" => "icon_type",
                    "value"   => "reach",
                ),
            ),
4

1 回答 1

0

您的问题可能出在您的参数声明代码中。尝试以下代码

array(
      'type' => 'iconpicker',
      'heading' => __( 'Button Icon', 'reach-rdp' ),
      'param_name' => 'reach_vc_button_icon',
      'settings' => array(
        'emptyIcon' => false, // default true, display an "EMPTY" icon?
        'type' => 'openiconic',
        'iconsPerPage' => 200, // default 100, how many icons per/page to display
      ),
      'dependency' => array(
        'element' => 'icon_type',
        'value' => 'openiconic',
      ),
      'description' => __( 'Select icon from library.', 'reach-rdp' ),
    ),

下一步是将 Openiconic 样式排入队列或在短代码输出文件中使用 Visual Composer 给定函数。遵循此代码

vc_icon_element_fonts_enqueue( $i_type );

有关详细信息,请查看此链接https://wpbakery.atlassian.net/wiki/display/VC/Adding+Icons+to+vc_icon

于 2017-01-26T10:44:43.480 回答