【问题标题】:PHP: Wordpress shortcode with imagePHP:带有图像的 Wordpress 简码
【发布时间】:2014-02-20 16:35:21
【问题描述】:

我的简码有问题。

看看这个主题: http://themeforest.net/item/elogix-responsive-business-wordpress-theme/full_screen_preview/1958520

请导航到“Shortcodes-> Toggle”并查看示例。

我想使用工具栏功能,但是,我希望能够在标题旁边使用图像,例如符号。

但是,当我在 wordpress 中执行此操作时,将不会显示标题,并且短代码会变得混乱。

核心代码如下:

function minti_toggle( $atts, $content = null)
    {
     extract(shortcode_atts(array(
            'title' => '',
            ), $atts));
       return '<div class="toggle"><div class="title">'.$title.'<span></span></div><div class="inner"><div>'. do_shortcode($content) . '</div></div></div>';
    } 

add_shortcode('toggle', 'minti_toggle');

我还是 PHP 的新手,所以我似乎看不到,它限制我只能在标题标签中使用字母,而不是图像文件。

最好的问候 帕特里克

【问题讨论】:

    标签: php wordpress image shortcode


    【解决方案1】:

    好的,我找到了问题所在,如果其他人需要这个:

    问题是,添加标签时,它会破坏标题标签,并且不显示任何内容。

    所以我编辑了代码,所以我可以输入另一个值,然后将其显示在标题的左侧:

        function minti_toggle($atts, $content = null)
    {
     extract(shortcode_atts(array(
            'title' => '',
            'image' => ''
            ), $atts));
       return '<div class="toggle"><div class="title">'.$title.'<span style="float:left;margin-right:5%"><img width="22" height="22" src="'.$image.'" class="alignnone wp-image-157"></span></div><div class="inner"><div>'. do_shortcode($content) . '</div></div></div>';
    }
    
        add_shortcode('toggle', 'minti_toggle');
    

    此代码返回图像的代码输入。所以简码是

    如果您希望能够在 css 文件中编辑代码,只需删除 中的样式,并在 style.css 中为此创建一个类。

    希望这可以帮助某人:)

    【讨论】:

    • 我正在尝试做类似的事情。您能否在帖子中展示您如何调用短代码?谢谢!
    【解决方案2】:

    用于在标题中设置背景图片。
    请修改插件的.css文件。

    .title{
       background:url('imageurl');
       background-repeat: no-repeat;
     }
    

    【讨论】:

    • 嘿!感谢您的回答。这不是我需要的背景图像,而是标题右侧的单个图像。示例:比利时(国旗图片)怎么可能做到这一点?
    猜你喜欢
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多