快捷码-在文本前显示内联图标

时间:2016-05-16 作者:Thomas.D

我创建了带有短代码的按钮,我需要在第一个文本之前添加图标,如下所示http://s32.postimg.org/codndv6s5/Bez_n_zvu.jpg

这是短代码

[button iconurl="http://www.yakna.cz/neuroportal/wp-content/themes/cityguide/design/img/child.png"  title="Děti" description="Rozcestník pro děti a mladistvé do 15 let" marginright="0%" width="45%" iconalign="top" textalign="center" align="left" url="http://www.yakna.cz/neuroportal/cat/deti/" bgcolor="#00968f"] [button iconurl="http://www.yakna.cz/neuroportal/wp-content/themes/cityguide/design/img/man.png" title="Dospělí" description="Rozcestník pro dospělé" marginleft="0%" width="45%" iconalign="top" textalign="center" align="right" url="http://www.yakna.cz/neuroportal/cat/dospeli/" bgcolor="#00968f"] [rule type="clear"]
这里是网站>http://www.yakna.cz/neuroportal

请告知,谢谢

1 个回复
最合适的回答,由SO网友:cjbj 整理而成

您的短代码没有以正确的方式响应html。你有

<span class="icon">
    <img ...>
</span>
<span class="text">
    <span class="title"> ... </span>
    <span class="description"> ... </span>
</span>
这样,您就不能将图标和标题内联。您需要:

<span class="icon-title">
    <img ...>
    <span class="title"> ... </span>
</span>
<span class="description"> ... </span>
顺便说一句,这更多的是css,而不是WP

我(托马斯)发现:

<a
    href="<?php echo esc_url($attrs->url) ?>"
    <?php if($attrs->urlnewwindow != "" and $attrs->urlnewwindow == "1" ){
        echo \'target="_blank"\'; }
    ?>
    id="<?php echo $this->htmlId ?>"
    class="<?php echo $this->htmlClass, " align{$attrs->align} ", " buticon-{$attrs->iconalign} " ?> <?php if($attrs->iconurl != "") echo \'buticon\' ?> <?php if(($attrs->title == "") and ($attrs->description == "")) echo \'notext\' ?> <?php if(($attrs->title != "") and ($attrs->description == "") and ($attrs->iconurl == "")) echo \'simple\' ?>"
    style="<?php echo $style[0], $style[1], $style[5], $style[6], $style[7], $style[8] ?>"
>
    <span class="container">
        <span class="wrap">

            <?php if($attrs->iconurl != ""){ ?>
                <?php if($attrs->iconalign == "top" or $attrs->iconalign == "left") { ?>
                <span class="icon" style="<?php echo $style[4] ?>">
                    <img src="<?php echo esc_url($attrs->iconurl) ?>" alt="button icon">
                </span>
                <?php } ?>
            <?php }elseif(!empty($attrs->fonticon)){ ?>
                <?php if($attrs->iconalign == "top" or $attrs->iconalign == "left") { ?>
                    <span class="icon" style="<?php echo $style[4] ?>">
                        <i class="fa <?php echo esc_attr($attrs->fonticon) ?>" <?php if(!empty($attrs->titlecolor)) { ?>style="color: <?php echo esc_attr($attrs->titlecolor) ?>;"<?php } ?>></i>
                    </span>
                <?php } ?>
            <?php } ?>

            <?php if(($attrs->title != "") or ($attrs->description != "")) { ?>
            <span class="text" style="<?php echo $style[4] ?>">
                <?php if($attrs->title != ""){ ?>
                <span class="title" style="<?php echo $style[2] ?>">
                    <?php
                    if($attrs->escapetext != "" and $attrs->escapetext == "0"){
                        echo html_entity_decode($attrs->title);
                    } else {
                        echo esc_html($attrs->title);
                    }
                    ?>
                </span>
                <?php } ?>
                <?php if($attrs->description != ""){ ?>
                <span class="description" style="<?php echo $style[3] ?>">
                    <?php
                        if($attrs->escapetext != "" and $attrs->escapetext == "0"){
                            echo html_entity_decode($attrs->description);
                        } else {
                            echo esc_html($attrs->description);
                        }
                        ?>
                </span>
                <?php } ?>
            </span>
            <?php } ?>

            <?php if($attrs->iconurl != ""){ ?>
                <?php if($attrs->iconalign == "bottom" or $attrs->iconalign == "right") { ?>
                <span class="icon" style="<?php echo $style[4] ?>">
                    <img src="<?php echo esc_url($attrs->iconurl) ?>" alt="button icon">
                </span>
                <?php } ?>
            <?php }elseif(!empty($attrs->fonticon)){ ?>
                <?php if($attrs->iconalign == "bottom" or $attrs->iconalign == "right") { ?>
                    <span class="icon" style="<?php echo $style[4] ?>">
                        <i class="fa <?php echo esc_attr($attrs->fonticon) ?>" <?php if(!empty($attrs->titlecolor)) { ?>style="color: <?php echo esc_attr($attrs->titlecolor) ?>;"<?php } ?>></i>
                    </span>
                <?php } ?>
            <?php } ?>
        </span>
    </span>
</a>

相关推荐

SHORTCODE_ATTS()中的$ATTS参数是什么?

这个WordPress developers reference page for shortcode_atts() 国家:$atts(array)(必选)用户在shortcode标记中定义的属性。但我不理解这个定义。例如,在WP Frontend Profile 插件:$atts = shortcode_atts( [ \'role\' => \'\', ], $atts ); 据我所知,shortcode\