如何在WordPress中使用ACF将多个图像添加到自定义页面模板中?
我有许多页面(400),它们都在视觉编辑器(Divi)中单独构建,尽管它们除了每个页面上的图像以外都是相同的 - 这是我的第一个网站,所以当我知道时,我不知道这种方法。我开始了。
它们都是pagex的儿童页面,他们的slug始于一个通用词。例如:
mysite.com/pagex/commonword-page1/
mysite.com/pagex/commonword-page2/
如果我想使用自定义页面模板并插入每个页面的唯一图像,我该怎么做?每个页面添加一个高级自定义字段,包含图像ID/URL数组是一个不错的选择吗?然后只需调用这个并循环遍历每个循环并插入DOM?
I have a number of pages (400) which are all build individually in a visual editor (DIVI), even though they are identical other than the images on each page - This was my first website and so I knew no better than this approach when I began.
They are all child-pages of pageX and their slug begins with a common word. eg:
mysite.com/pageX/commonword-page1/
mysite.com/pageX/commonword-page2/
If I wanted to use a custom page template and insert unique images for each page, how would I go about doing this? Would adding an advanced custom field for each page containing an array of image ids/urls be a good option? Then simply call this and loop through each one and insert into the DOM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您将从插件目录下载并安装ACF。然后,创建一个自定义画廊字段。
在页面上,使用自定义字段,在图库中选择所需的图像。然后在模板中使用此代码来创建WordPress图库:
从Gallery Fields的ACF文档中提取。
这是他们的链接:
You would download and install ACF from the Plugins directory. Then, create a custom gallery field.
On the page, using the custom field, select the images you want in the gallery. Then in the template, to create a WordPress Gallery use this code:
This was pulled from the ACF documentation for gallery fields.
Here is their link:
https://www.advancedcustomfields.com/resources/gallery/