在function.php中包含ACF(WordPress)

前端之家收集整理的这篇文章主要介绍了在function.php中包含ACF(WordPress)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在制作一个主题,以第一次出售主题forrest.我在开发过程中使用ACF作为标准插件,以确保一切正常.

我差不多完成所以决定将我的ACF导出到PHP并将其包含在我的functions.PHP文件中.

我将它给我的代码复制/粘贴到functions.PHP中,并将ACF,options-page和repeater-field包含在我主题中的文件夹中,并相应地引用它们.

但是,当我访问我的网站时,我收到此错误

致命错误:无法在第46行的/Applications/MAMP/htdocs/omg/wp-content/themes/omg-v1/external/acf/acf.PHP中重新声明类Acf

我也从插件文件夹中删除了实际的插件文件.

任何想法为什么它可能会被淘汰?

我知道这是很多代码,但是任何人都希望看到这是我的functions.PHP中的代码(ACF给了我)

include_once('external/acf/acf.PHP' );
define( 'ACF_LITE',true );

// Add-ons 
include_once('external/acf-repeater/acf-repeater.PHP');
include_once('external/acf-options-page/acf-options-page.PHP');



if(function_exists("register_field_group"))
{
    register_field_group(array (
        'id' => 'acf_featured-story','title' => 'Featured Story','fields' => array (
            array (
                'key' => 'field_5256bd0fc7592','label' => 'Is this story featured?','name' => 'featured-story','type' => 'true_false','message' => 'Yes','default_value' => 0,),'location' => array (
            array (
                array (
                    'param' => 'post_type','operator' => '==','value' => 'post','order_no' => 0,'group_no' => 0,'options' => array (
            'position' => 'side','layout' => 'default','hide_on_screen' => array (
            ),'menu_order' => 0,));
    register_field_group(array (
        'id' => 'acf_options','title' => 'Options','fields' => array (
            array (
                'key' => 'field_525d1b6d49043','label' => 'Homepage Layout (Left Column)','name' => 'homepage-layout-left','type' => 'repeater','instructions' => 'Select which categories you want to display on the homepage.','sub_fields' => array (
                    array (
                        'key' => 'field_525d1b8a49044','label' => 'Category','name' => 'category','type' => 'taxonomy','column_width' => '','taxonomy' => 'category','field_type' => 'select','allow_null' => 0,'load_save_terms' => 0,'return_format' => 'id','multiple' => 0,array (
                        'key' => 'field_525d2473de72c','label' => 'Number of Posts','name' => 'number-of-posts','type' => 'number','default_value' => 4,'placeholder' => '','prepend' => '','append' => '','min' => 2,'max' => '','step' => 2,'row_min' => 1,'row_limit' => 4,'layout' => 'row','button_label' => 'Add a category',array (
                'key' => 'field_525d25ee91b41','label' => 'Homepage Layout (Sidebar)','name' => 'homepage-layout-sidebar','instructions' => 'Select which categories you want to display in the sidebar.','sub_fields' => array (
                    array (
                        'key' => 'field_525d25ee91b42',array (
                        'key' => 'field_525d25ee91b43',array (
                'key' => 'field_525d2afdf101b','label' => 'Newsletter (optional)','name' => 'newsletter','sub_fields' => array (
                    array (
                        'key' => 'field_525d2b6612426','label' => 'Link','name' => 'link','type' => 'text','instructions' => 'If you have a newsletter,copy/paste your link in here.','default_value' => '','formatting' => 'none','maxlength' => '',array (
                        'key' => 'field_525d2bb40e332','label' => 'Text','name' => 'text','type' => 'textarea','instructions' => 'Enter your call to action for the newsletter here.','default_value' => 'Subscribe!

                        To the OMG! newsletter!','maxlength' => 100,'formatting' => 'br','row_min' => 0,'row_limit' => 1,'button_label' => 'Add Newsletter Link',array (
                'key' => 'field_525e8b77edf6e','label' => 'Advert','name' => 'adverts','instructions' => 'Do you wish to display an advert in your sidebar?','sub_fields' => array (
                    array (
                        'key' => 'field_525e8c1e3600f','label' => 'Advert Image','name' => 'advert-img','type' => 'image','instructions' => 'Upload a 300 x 200px image for best quality / load time','save_format' => 'url','preview_size' => 'full','library' => 'all',array (
                        'key' => 'field_525e8d1699619','name' => 'ad-link','layout' => 'table','button_label' => 'Add an Advert','location' => array (
            array (
                array (
                    'param' => 'options_page','value' => 'acf-options','options' => array (
            'position' => 'normal','layout' => 'no_Box',));
}
您需要确保您的包含不会与ACF本身或其他也使用它的插件发生冲突.
if( !class_exists('Acf') )
    include_once('external/acf/acf.PHP' );

if( !class_exists('acf_repeater_plugin') )
    include_once('external/acf-repeater/acf-repeater.PHP');

if( !class_exists('acf_options_page_plugin') )
    include_once('external/acf-options-page/acf-options-page.PHP');

猜你在找的PHP相关文章