premiummedia / acfcontentpress
ACF Field(Group)s via PHP
1.2.4
2018-04-10 15:33 UTC
Requires
- php: >=5.4
README
What's up?
- Create Advanced Custom Field Groups using php
See the documentation for more information. https://acf-contentpress.readthedocs.io
Installation
- Using composer or download and move to your plugin directory
NOTE: ACF is required for this to work. ACF PRO recommended to use Flexible Content Fields and other good stuff.
Usage
- Create a new directory
contents
in your active theme directory. - Add directories in
contents
forfieldgroups
andlayouts
as needed. - Create a seperate file for each group/layout in their respective directories.
FieldGroups
Create field groups by creating a file in the contents/fieldgroups
folder.
Eg. contents/fieldgroups/headerfieldgroup.php
<?php
return [
ACFCP::APPLIESTO => [
'page'
],
ACFCP::FIELDS => [
[
ACFCP::REPEATERFIELD,
'slider',
[
'min' => 1,
'button_label' => 'Add Image'
],
ACFCP::FIELDS => [
[
ACFCP::IMAGEFIELD,
'image'
],
[
ACFCP::TEXTFIELD,
'caption',
'Image Caption',
[
'maxlength' => 64
]
]
]
]
]
];
Layouts
Layouts are a collection of fields, which can be added to a flexible content field.
Create layouts by creating a file in the contents/layouts
folder.
Eg. contents/layouts/paragraphlayout.php
<?php
return [
ACFCP::FIELDS => [
[
ACFCP::TEXTFIELD,
'title',
],
[
ACFCP::TEXTAREAFIELD,
'text'
],
],
ACFCP::SETTINGS => [
'label' => 'Paragraph'
]
];
Add the layout to a flexible content field: (within a field group field)
[
ACFCP::FLEXIBLECONTENTFIELD,
'multicontent',
ACFCP::LAYOUTS => [
'paragraphlayout',
'downloadlayout'
]
],