ACF Archives is a little plugin for helping you attach ACF fields to the archive template.
ACF Archives是一个小插件,可帮助您将ACF字段附加到存档模板。
The plugin will add a submenu for each public custom post type with archive defined
该插件将为每种公共自定义帖子类型添加一个子菜单,其中定义了存档
and then you can select under ACF rules box.
然后您可以在“ ACF规则”框中选择。 p>
Want to add or remove the submenu for other custom post types?
是否要添加或删除其他自定义帖子类型的子菜单? h3>
Here is a code example you can add to to your theme functions.php
这是一个代码示例,您可以将其添加到主题函数中。php p>
add_filter( 'acf_archive_post_types', 'change_acf_archive_cpt' ); add_filter('acf_archive_post_types','change_acf_archive_cpt'); function change_acf_archive_cpt( $cpts ) {
函数change_acf_archive_cpt($ cpts){
// 'book' and 'movie' are the cpt key.
//'book'和'movie'是cpt键。
// Remove cpt
//删除cpt
unset( $cpts['book'] );
unset($ cpts ['book']);
// Add cpt
//添加cpt
$cpts['movie'] = Movies Archive;
$ cpts ['movie'] =电影档案;
return $cpts;
返回$ cpts;
}
}
code> pre>
Get the acf field on archive page
在存档页面上获取acf字段 h3>
$object = get_queried_object(); $ object = get_queried_object(); $field = get_field( 'field_name', $object->name );
$ field = get_field('field_name',$ object-> name);
var_dump( $field );
var_dump($ field);
code> pre>
From within WordPress
在WordPress内部 h3>
- Visit ‘Plugins > Add New’
- 访问“插件>添加新内容” li>
- Search for ‘acf archive’
- 搜索“ acf存档” li>
- Activate ACF Archive from your Plugins page.
- 从“插件”页面激活ACF存档。 li>
ol>
Manually
手动 h3>
- Upload the
acf-archive
folder to the /wp-content/plugins/
directory - 将
acf-archive code>文件夹上传到 / wp-content / plugins / code>目录 li>- Activate the ACF Archive plugin through the ‘Plugins’ menu in WordPress
- 通过WordPress中的“插件”菜单激活ACF存档插件 li>
ol>