如何使自定义metabox字段可复制? [英] How to make custom metabox fields duplicatable?

查看:108
本文介绍了如何使自定义metabox字段可复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在为WordPress管理员编写插件.这是关于自定义元框.我想创建一个幻灯片插件,只是为了学习很多编码.

I am now currently coding a plugin for the WordPress admin. It's about custom meta boxes. I would like to create a slideshow plugin, just for learning a lot of coding.

我创建了一个metabox,其中包含一个图片上传和一个文本输入字段. (请参见下面的图片)

I have created one metabox, that contains an image upload and a text input field. (see picture bellow)

如此,我可以保存字段,这样我就可以上传图像并在文本字段内为其设置Capton.当我在WordPress中保存帖子/页面时,它将在我的数据库中保存我的值.很好!

So on, I can save the fields, so I can upload an image and set an capton to it inside the text field. When I save the post/page inside WordPress it will save the values for me in my database. That's fine!

现在,我想通过用户添加和删除字段(如可重复字段)的方式来扩展代码.
如上图所示,我创建了添加新的幻灯片按钮,还编写了一些JavaScript使其正常工作,但这无法正常工作.

Now I would like to expand the code, through the user possibility to add and remove fields, like, repeatable field.
As you can see in the image above, I have created the add new slide button, I have also code some javascript for get it work, but this doesn't work correctly.

所以我想问的是,动态创建字段的最佳方法是什么?
我现在正在使用javascript中的clone函数来克隆字段,但只有默认行会起作用.

So my question to you is, what's the best way to create dynamically fields?
I am now using the clone function in javascript, to clone the fields, but only the default row will work.

我已经使用了几个星期,到目前为止还没有找到解决方案.

I've been a few weeks with it and couldn't find a solution so far.

某些代码:
这是用PHP创建的我的metabox代码 这是我现在使用的 jQuery/Java

Some code:
This is the code of my metabox created with PHP
This is the jQuery / Javascript that I'm using now

推荐答案

我已经回答了许多问题关于WordPress StackExchange中的此主题.
它称为可重复字段.

I've answered many Questions regarding this topic in WordPress StackExchange.
It is called Repeatable Fields.

但是基本上这些是必需的资源:

But basically these are the needed resources:

  • Create more Meta Boxes as needed - WPSE Q&A

Metabox中可重复的自定义字段-要点

/**
 * Repeatable Custom Fields in a Metabox
 * Author: Helen Hou-Sandi
 *
 * From a bespoke system, so currently not modular - will fix soon
 * Note that this particular metadata is saved as one multidimensional array (serialized)
 */

  • Metabox中可重复的自定义字段-另一个Gist示例,未给出描述

  • Repeatable Custom Fields in a Metabox - Another Gist example, no description given

    这篇关于如何使自定义metabox字段可复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆