Пример #1
0
function have_rows($field_name, $post_id = false)
{
    // vars
    $depth = 0;
    $row = array();
    $new_parent_loop = false;
    $new_child_loop = false;
    // reference
    $_post_id = $post_id;
    // filter post_id
    $post_id = apply_filters('acf/get_post_id', $post_id);
    // empty?
    if (empty($GLOBALS['acf_field'])) {
        // reset
        reset_rows(true);
        // create a new loop
        $new_parent_loop = true;
    } else {
        // vars
        $row = end($GLOBALS['acf_field']);
        $prev = prev($GLOBALS['acf_field']);
        // If post_id has changed, this is most likely an archive loop
        if ($post_id != $row['post_id']) {
            if ($prev && $prev['post_id'] == $post_id) {
                // case: Change in $post_id was due to a nested loop ending
                // action: move up one level through the loops
                reset_rows();
            } elseif (empty($_post_id) && isset($row['value'][$row['i']][$field_name])) {
                // case: Change in $post_id was due to this being a nested loop and not specifying the $post_id
                // action: move down one level into a new loop
                $new_child_loop = true;
            } else {
                // case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects
                // action: leave this current loop alone and create a new parent loop
                $new_parent_loop = true;
            }
        } elseif ($field_name != $row['name']) {
            if ($prev && $prev['name'] == $field_name && $prev['post_id'] == $post_id) {
                // case: Change in $field_name was due to a nested loop ending
                // action: move up one level through the loops
                reset_rows();
            } elseif (isset($row['value'][$row['i']][$field_name])) {
                // case: Change in $field_name was due to this being a nested loop
                // action: move down one level into a new loop
                $new_child_loop = true;
            } else {
                // case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post
                // action: leave this current loop alone and create a new parent loop
                $new_parent_loop = true;
            }
        }
    }
    if ($new_parent_loop) {
        // vars
        $f = get_field_object($field_name, $post_id);
        $v = $f['value'];
        unset($f['value']);
        // add row
        $GLOBALS['acf_field'][] = array('name' => $field_name, 'value' => $v, 'field' => $f, 'i' => -1, 'post_id' => $post_id);
    } elseif ($new_child_loop) {
        // vars
        $f = acf_get_child_field_from_parent_field($field_name, $row['field']);
        $v = $row['value'][$row['i']][$field_name];
        $GLOBALS['acf_field'][] = array('name' => $field_name, 'value' => $v, 'field' => $f, 'i' => -1, 'post_id' => $post_id);
    }
    // update vars
    $row = end($GLOBALS['acf_field']);
    if (is_array($row['value']) && array_key_exists($row['i'] + 1, $row['value'])) {
        // next row exists
        return true;
    }
    // no next row!
    reset_rows();
    // return
    return false;
}
Пример #2
0
function reset_the_repeater_field()
{
    return reset_rows();
}
        function render_layout($field, $layout, $i, $value)
        {
            // vars
            $order = 0;
            $el = 'div';
            $div = array('class' => 'layout', 'data-id' => $i, 'data-layout' => $layout['name']);
            // collapsed class
            if (acf_is_row_collapsed($field['key'], $i)) {
                $div['class'] .= ' -collapsed';
            }
            // clone
            if (is_numeric($i)) {
                $order = $i + 1;
            } else {
                $div['class'] .= ' acf-clone';
            }
            // title
            $title = $this->get_layout_title($field, $layout, $i, $value);
            // remove row
            reset_rows();
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
			
	<div class="acf-hidden">
		<?php 
            acf_hidden_input(array('name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name']));
            ?>
	</div>
	
	<div class="acf-fc-layout-handle" title="<?php 
            _e('Drag to reorder', 'acf');
            ?>
"><?php 
            echo $title;
            ?>
</div>
	
	<ul class="acf-fc-layout-controlls acf-hl">
		<li class="acf-fc-show-on-hover">
			<a class="acf-icon -plus small" href="#" data-event="add-layout" title="<?php 
            _e('Add layout', 'acf');
            ?>
"></a>
		</li>
		<li class="acf-fc-show-on-hover">
			<a class="acf-icon -minus small" href="#" data-event="remove-layout" title="<?php 
            _e('Remove layout', 'acf');
            ?>
"></a>
		</li>
		<li>
			<a class="acf-icon -collapse small" href="#" data-event="collapse-layout" title="<?php 
            _e('Click to toggle', 'acf');
            ?>
"></a>
		</li>
	</ul>
	
<?php 
            if (!empty($layout['sub_fields'])) {
                ?>
	
	<?php 
                if ($layout['display'] == 'table') {
                    // update vars
                    $el = 'td';
                    ?>
	<table class="acf-table">
		
		<thead>
			<tr>
				<?php 
                    foreach ($layout['sub_fields'] as $sub_field) {
                        $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']);
                        // Add custom width
                        if ($sub_field['wrapper']['width']) {
                            $atts['data-width'] = $sub_field['wrapper']['width'];
                        }
                        ?>
					<th <?php 
                        acf_esc_attr_e($atts);
                        ?>
>
						<?php 
                        echo acf_get_field_label($sub_field);
                        ?>
						<?php 
                        if ($sub_field['instructions']) {
                            ?>
							<p class="description"><?php 
                            echo $sub_field['instructions'];
                            ?>
</p>
						<?php 
                        }
                        ?>
					</th>
					
				<?php 
                    }
                    ?>
 
			</tr>
		</thead>
		
		<tbody>
	<?php 
                } else {
                    ?>
	<div class="acf-fields <?php 
                    if ($layout['display'] == 'row') {
                        ?>
-left<?php 
                    }
                    ?>
">
	<?php 
                }
                ?>
	
		<?php 
                // loop though sub fields
                foreach ($layout['sub_fields'] as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($value[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $value[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = "{$field['name']}[{$i}]";
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                }
                ?>
			
	<?php 
                if ($layout['display'] == 'table') {
                    ?>
		</tbody>
	</table>
	<?php 
                } else {
                    ?>
	</div>
	<?php 
                }
                ?>

<?php 
            }
            ?>

</div>
<?php 
        }
function have_rows($field_name, $post_id = false)
{
    // vars
    $depth = 0;
    $row = array();
    $new_parent_loop = false;
    $new_child_loop = false;
    $no_post_id = !$post_id ? true : false;
    // filter post_id
    $post_id = apply_filters('acf/get_post_id', $post_id);
    // empty?
    if (empty($GLOBALS['acf_field'])) {
        // reset
        reset_rows(true);
        // create a new loop
        $new_parent_loop = true;
    } else {
        // vars
        $row = end($GLOBALS['acf_field']);
        $prev = prev($GLOBALS['acf_field']);
        // detect a change in params?
        if ($post_id != $row['post_id'] || $field_name != $row['name']) {
            // case: previous have_rows loop was terminated early and template is now loading row data from another $post
            // case: previous have_rows loop was terminated early and template is now loading row data from another $field_name
            // case: nested have_rows loop
            $new_parent_loop = true;
            if (isset($row['value'][$row['i']][$field_name])) {
                // Inception: Repeater within repeater
                // Note: Sit back and enter the next level of dream
                $new_child_loop = true;
                // It is possible that the origional have_rows function used a custom $post_id param, but this sub loop did not use one. If so, remove the potential to create a new parent loop due to the $post_id change!
                if ($no_post_id || $post_id == $row['post_id']) {
                    $new_parent_loop = false;
                }
            } elseif ($prev && $prev['name'] == $field_name) {
                // Inception: Ride kick up one level
                // Note: This can happen if someone used break or ran out of rows
                reset_rows();
                $new_parent_loop = false;
            }
        }
    }
    if ($new_parent_loop) {
        // vars
        $f = get_field_object($field_name, $post_id);
        $v = $f['value'];
        unset($f['value']);
        // add row
        $GLOBALS['acf_field'][] = array('name' => $field_name, 'value' => $v, 'field' => $f, 'i' => -1, 'post_id' => $post_id);
    } elseif ($new_child_loop) {
        // vars
        $f = acf_get_child_field_from_parent_field($field_name, $row['field']);
        $v = $row['value'][$row['i']][$field_name];
        $GLOBALS['acf_field'][] = array('name' => $field_name, 'value' => $v, 'field' => $f, 'i' => -1, 'post_id' => $post_id);
    }
    // update vars
    $row = end($GLOBALS['acf_field']);
    if (is_array($row['value']) && array_key_exists($row['i'] + 1, $row['value'])) {
        // next row exists
        return true;
    }
    // no newxt row!
    reset_rows();
    // return
    return false;
}
Пример #5
0
                /**
                 * Get gallery image
                 */
                echo wp_get_attachment_image(get_sub_field('gallery_image'), 'slide-wide', array('alt' => 'image'));
                ?>

                                            </li>



                                        <?php 
                if ($i++ == 5) {
                    break;
                }
            }
            reset_rows();
            ?>


                                    </ul>



                                <?php 
        } else {
            ?>



                                    <?php 
            _e('No Gallery found', 'atu');