简体   繁体   English

PHP:带有图像的Wordpress简码

[英]PHP: Wordpress shortcode with image

I have a problem with a shortcode. 我的简码有问题。

Check this theme out: http://themeforest.net/item/elogix-responsive-business-wordpress-theme/full_screen_preview/1958520 查看此主题: http : //themeforest.net/item/elogix-sensitive-business-wordpress-theme/full_screen_preview/1958520

Please navigate to "Shortcodes-> Toggle" and see the example. 请导航至“ Shortcodes-> Toggle”,然后查看示例。

I want to use the toogle function, however, i want to be able to use an image beside the title, like a symbol. 我想使用toogle函数,但是,我希望能够在标题旁边使用图像,例如符号。

However, when i do this within wordpress, the title will not be shown, and the shortcode gets messed up. 但是,当我在wordpress中执行此操作时,标题将不会显示,并且简码会混乱。

The core code looks like this: 核心代码如下所示:

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');

I am still new at PHP, so I cannot seem to see, where it limits me to only use letters within the title tag, and not an image file as well. 我对PHP还是很陌生,所以似乎看不到,它限制了我只能在title标签中使用字母,而不能使用图像文件。

Best Regards Patrick 最好的问候帕特里克

Okay, so i figured out the problem, if anyone else needs this: 好的,所以我想出了问题,如果还有其他人需要这样做:

The problem was, when adding a tag, it would disrupt the title tag, and not display anything. 问题是,添加标签时,它将破坏标题标签,并且不显示任何内容。

So i edited the code, so i could input another value, which would then be showed left to the title: 所以我编辑了代码,所以我可以输入另一个值,然后将其显示在标题的左侧:

    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');

This code returns the code input for image. 此代码返回输入的图像代码。 So the shortcode would be 所以简码是

If you want to be able to edit the code in a css file instead, just delete the style in the , and make a class for this in the style.css. 如果您希望能够编辑css文件中的代码,只需删除中的样式,然后在style.css中为此创建一个类。

Hope this helps someone :) 希望这可以帮助某人:)

For Setting background image in title. 用于在标题中设置背景图像。
Please make change in .css file of plugins. 请在插件的.css文件中进行更改。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM