PHP:带图像的Wordpress短代码(PHP: Wordpress shortcode with image)

编程入门 行业动态 更新时间:2024-10-24 20:14:32
PHP:带图像的Wordpress短代码(PHP: Wordpress shortcode with image)

我有一个短代码的问题。

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

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

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

但是,当我在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的新手,所以我似乎无法看到,它限制我只使用title标签内的字母,而不是图像文件。

最好的问候帕特里克

I have a problem with a shortcode.

Check this theme out: http://themeforest.net/item/elogix-responsive-business-wordpress-theme/full_screen_preview/1958520

Please navigate to "Shortcodes-> Toggle" and see the example.

I want to use the toogle function, however, i want to be able to use an image beside the title, like a symbol.

However, when i do this within wordpress, the title will not be shown, and the shortcode gets messed up.

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.

Best Regards Patrick

最满意答案

好的,所以我想出了问题,如果有其他人需要这个:

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

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

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中为此创建一个类。

希望这有助于某人:)

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.

Hope this helps someone :)

更多推荐

本文发布于:2023-07-24 10:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1245021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   代码   PHP   Wordpress   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!