【发布时间】:2014-03-21 15:06:44
【问题描述】:
我正在为 wordpress.org 开发一个 WordPress 插件,这是我的第一个插件。有一个我自己无法解决的问题(我做了很多谷歌但仍然找不到任何解决方案)。但也许这个问题的解决方案对你们中的一些人来说非常简单。因此,如果您知道直接的解决方案,请回答;我将不胜感激。
我的插件允许用户为每列制作带有横幅图像的表格。请检查此demo link。
每列的标题部分有两个部分。一个是subject,另一个是image。简码看起来像
[head subject="Standard" image="http://shahriarblog.com/wp-content/uploads/2014/03/hello-5.jpg "][/head]
上述短代码的源代码如下:
function head($atts, $content = null) {
extract( shortcode_atts( array(
'color' => '#333',
'banner' => 'visible',
'subject' => 'Subject',
'image' => 'http://shahriarblog.com/wp-content/uploads/2014/03/hello-5.jpg',
), $atts ) );
return "<div class='gridacc'><h2 style='background:{$color}'>{$subject}</h2><div class='photo' style='display: {$banner}ne'><img src='{$image}' alt=''></div><dl>".do_shortcode($content)."</dl></div>";
}
add_shortcode ("head", "head");
如您所见,用户必须知道图像的 url 才能在短代码中使用它们。但我不想使用图片网址,而是只使用图片名称。例如,我想使用 image="hello-5.jpg" 而不是使用 image="http://shahriarblog.com/wp-content/uploads/2014 /03/hello-5.jpg"
另一件事: 现在要获取图片的 url,每个用户都需要通过 WordPress Media 上传图片,然后从媒体库中获取每张图片的 url。但是是否可以直接在我的插件文件夹而不是默认的 WordPress Uploads 文件夹中上传图像?
这里是 link 该插件的文档和source code,如果您有兴趣。非常感谢。
【问题讨论】: