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

时间:2016-04-22 20:52:35

标签: php wordpress advanced-custom-fields

我正在使用第二个自定义帖子类型在flex内容布局中设置默认主题值。下面是我的工作代码,但是,它有点冗长,我想知道这是否是比较两者的正确方法。如果帖子具有该字段的值,则使用该值 - 如果不是,则从第二个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; ?>;">

0 个答案:

没有答案