Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hhs_repeatable_meta_box_display()
- {
- global $post;
- $repeatable_fields = get_post_meta($post->ID, 'repeatable_fields', true);
- wp_nonce_field('hhs_repeatable_meta_box_nonce', 'hhs_repeatable_meta_box_nonce');
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function ($) {
- $('#add-row').on('click', function () {
- var row = $('.empty-row.screen-reader-text').clone(true);
- row.removeClass('empty-row screen-reader-text');
- row.insertBefore('#repeatable-fieldset-one tbody>tr:last');
- return false;
- });
- $('.remove-row').on('click', function () {
- $(this).parents('tr').remove();
- return false;
- });
- });
- </script>
- <table id="repeatable-fieldset-one" width="100%">
- <thead>
- <tr>
- <th width="25%">Name</th>
- <th width="10%">Date</th>
- <th width="40%">Text</th>
- <th width="25%">Image</th>
- </tr>
- </thead>
- <tbody>
- <?php $meta = get_post_meta($post->ID, $repeatable_fields['image'], true); ?>
- <?php
- if ($repeatable_fields) :
- foreach ($repeatable_fields as $field) {
- ?>
- <!-- FRONT - EDITABLE -->
- <tr>
- <td><input type="text" class="widefat" name="name[]"
- value="<?php if ($field['name'] != '') echo esc_attr($field['name']); ?>"/></td>
- <td><input type="text" class="widefat" name="date[]"
- value="<?php if ($field['date'] != '') echo esc_attr($field['date']); ?>"/></td>
- <td><input type="text" class="widefat" name="text[]"
- value="<?php if ($field['text'] != '') echo esc_attr($field['text']); ?>"/></td>
- <td>
- <?php
- if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
- ?>
- <input type="hidden" class="custom_upload_image" name="image[]"
- value="<?php if ($field['image'] != '') echo esc_attr($field['image']); ?>"/>
- <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
- <input class="custom_upload_image_button button" type="button" value="Choose Image" />
- <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
- <td><a class="button remove-row" href="#">Remove</a></td>
- </tr>
- <?php
- }
- else :
- // BLANK ONE
- ?>
- <tr>
- <td><input type="text" class="widefat" name="name[]"/></td>
- <td><input type="text" class="widefat" name="date[]"/></td>
- <td><input type="text" class="widefat" name="text[]"/></td>
- <td>
- <?php
- $image = get_template_directory_uri().'/images/image.png';
- echo '<span class="custom_default_image" style="display:none">'.$image.'</span>';
- if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
- ?>
- <input type="hidden" class="custom_upload_image" name="image[]"/>
- <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
- <input class="custom_upload_image_button button" type="button" value="Choose Image" />
- <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
- <td><a class="button remove-row" href="#">Remove</a></td>
- </tr>
- <?php endif; ?>
- <!-- empty hidden one for jQuery
- LOAD THIS ONE IN !
- -->
- <tr class="empty-row screen-reader-text">
- <td><input type="text" class="widefat" name="name[]"/></td>
- <td><input type="text" class="widefat" name="date[]"/></td>
- <td><input type="textarea" class="widefat" name="text[]"/></td>
- <td>
- <?php
- $image = get_template_directory_uri().'/images/image.png';
- echo '<span class="custom_default_image" style="display:none">'.$image.'</span>';
- if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
- ?>
- <input type="hidden" class="custom_upload_image" name="image[]"
- value="<?php if ($field['image'] != '') echo esc_attr($field['image']); ?>"/>
- <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
- <input class="custom_upload_image_button button" type="button" value="Choose Image" />
- <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
- <td><a class="button remove-row" href="#">Remove</a></td>
- </tr>
- </tbody>
- </table>
- <p><a id="add-row" class="button" href="#">Add another</a></p>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment