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
Php 如何使用ACF flex布局比较两种自定义帖子类型_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php 如何使用ACF flex布局比较两种自定义帖子类型

Php 如何使用ACF flex布局比较两种自定义帖子类型,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我使用第二个自定义帖子类型在flex内容布局中设置默认主题值。下面是我的工作代码,但是有点冗长,我想知道这是否是比较两者的正确方法。如果post具有字段值,则使用该值-如果没有,则从第二个CPT提取匹配的字段值 //theme vars $theme_padding = $theme_background_color = $theme_padding = $theme_height = $theme_color = $theme_font_family = $theme_font_size =

我使用第二个自定义帖子类型在flex内容布局中设置默认主题值。下面是我的工作代码,但是有点冗长,我想知道这是否是比较两者的正确方法。如果post具有字段值,则使用该值-如果没有,则从第二个CPT提取匹配的字段值

//theme vars
$theme_padding = $theme_background_color = $theme_padding = $theme_height = $theme_color = $theme_font_family = $theme_font_size = '';

$theme = get_field('theme_picker');

if( $theme ):

  foreach( $theme as $post):
    setup_postdata($post);
    while ( have_rows('nav') ) : the_row();

      if( get_row_layout() == 'right_aligned' ):

        $theme_background_color = get_sub_field('background_color');
        $theme_padding = get_sub_field('padding');
        $theme_height = get_sub_field('height');
        $theme_color = get_sub_field('color');
        $theme_font_family = get_sub_field('font_family');
        $theme_font_size = get_sub_field('font_size');

      endif;

    endwhile;

   endforeach;
   wp_reset_postdata();

 endif;

//var = if no post level theme var, use theme var
$background_color = get_sub_field('background_color') ?: $theme_background_color;
$padding = get_sub_field('padding') ?: $theme_padding;
$height = get_sub_field('height') ?: $theme_height;
$color = get_sub_field('color') ?: $theme_color;
$font_family = get_sub_field('font_family') ?: $theme_font_family;
$font_size = get_sub_field('font_size') ?: $theme_font_size;



// check if the repeater field has rows of data
if( have_rows('nav_type') ): ?>

<table bgcolor="<?php echo $background_color; ?>" class="emailwrapto100pc" border="0" cellspacing="0" cellpadding="0" style=" width:100%; height: <?php echo $height; ?>;">
//主题变量
$theme\u padding=$theme\u background\u color=$theme\u padding=$theme\u height=$theme\u color=$theme\u font\u family=$theme\u font\u size='';
$theme=get_字段('theme_picker');
如果($主题):
foreach(主题为$post):
设置_postdata($post);
while(have_rows('nav')):the_row();
如果(获取行布局()=“右对齐”):
$theme_background_color=get_sub_字段(“background_color”);
$theme_padding=get_sub_字段(“padding”);
$theme_height=获取子字段(“height”);
$theme_color=获取子字段('color');
$theme_font_family=获取子字段('font_family');
$theme_font_size=获取子字段('font_size');
endif;
结束时;
endforeach;
wp_reset_postdata();
endif;
//var=如果没有后期主题变量,则使用主题变量
$background\u color=获取子字段('background\u color')?:$theme\u background\u color;
$padding=get_sub_字段('padding')?:$theme_padding;
$height=获取子字段('height')?:$theme\u height;
$color=get_sub_字段('color')?:$theme_color;
$font\U family=获取子字段('font\U family')?:$theme\U font\U family;
$font\U size=获取子字段('font\U size')?:$theme\U font\U size;
//检查repeater字段是否有数据行
如果(有行(“导航类型”):?>