Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 管理不是文章或页面的内容_Wordpress_Wordpress Theming_Advanced Custom Fields - Fatal编程技术网

Wordpress 管理不是文章或页面的内容

Wordpress 管理不是文章或页面的内容,wordpress,wordpress-theming,advanced-custom-fields,Wordpress,Wordpress Theming,Advanced Custom Fields,我使用高级自定义字段按帖子(书籍)或页面(主页、联系人等)管理内容。但是,如果我想管理无法按帖子或页面组织的内容,如营业时间、企业名称、标语、徽标等,该怎么办 这些字段可能在整个网站的页眉、页脚、关于页面、联系人页面、主页等上多次出现。这些字段实际上不是帖子类型,为每个页面创建相同的自定义字段是多余的 有没有一种方法可以使用ACF管理内容,而不必按帖子或页面组织内容 比如: $fields = get_fields('general_info'); //not a page, not a pos

我使用高级自定义字段按帖子(书籍)或页面(主页、联系人等)管理内容。但是,如果我想管理无法按帖子或页面组织的内容,如营业时间、企业名称、标语、徽标等,该怎么办

这些字段可能在整个网站的页眉、页脚、关于页面、联系人页面、主页等上多次出现。这些字段实际上不是帖子类型,为每个页面创建相同的自定义字段是多余的

有没有一种方法可以使用ACF管理内容,而不必按帖子或页面组织内容

比如:

$fields = get_fields('general_info'); //not a page, not a post
echo $fields->site_name; //appears on every page
echo $fields->slogan; //appears on 70% of pages
echo $fields->logo; //appears on header, footer and about

ACF的选项页面是处理这个问题的一个很好的方法。首先在functions.php中注册选项页,类似于-

if( function_exists('acf_add_options_page') ) {

    acf_add_options_sub_page(array(
        'title' => 'Theme Options',
        'parent' => 'options-general.php',
        'capability' => 'manage_options'
    ));

}
这将在WP菜单的设置下放置一个新页面。然后,您可以将字段添加到此选项页面,并使用
get_field('field_name','option')在主题中检索它们

您可以使用,这是本机的。您只需将一个函数挂接到
customize\u register
action,并在其中创建节和设置/控件,如下所示:

function mytheme_customize_register( $wp_customize ) {
    $wp_customize->add_section('custom_footer', array(
       'title'    => 'Footer',
       'priority' => 125,
    ));
    $wp_customize->add_setting('copyright', array(
        'default'        => '',
        'capability'     => 'edit_theme_options',   
    )); 
    $wp_customize->add_control('copyright', array(
        'label'      => 'Copyright',
        'section'    => 'custom_footer',
        'settings'   => 'copyright',
    ));
}
add_action('customize_register', 'mytheme_customize_register');
要使用这些值,只需调用

get_theme_mod('copyright');

希望有帮助

很好的回答-我从来都不知道ACF中的这个特性。这个插件的功能让我惊叹不已!