Advertisement
luisabarca

Custom fields metabox

Oct 19th, 2011
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <style>
  2. #adjuntos .line {    
  3.     margin: 4px 0;
  4.     padding: 0;
  5.     border: 0;
  6.     margin: 0;
  7. }
  8. #adjuntos .line td {
  9.     padding: 4px;
  10.     margin: 4px 0;
  11.     border-top: 1px solid #dfdfdf;
  12. }
  13.  
  14. #adjuntos {
  15.     width: 100%;
  16.     border: 0;
  17.     padding: 0;
  18. }
  19. </style>
  20.  
  21.  
  22. <table id="template" style="display: none">
  23.     <tr class="line">
  24.         <td width="40%">
  25.         <label><?php _e('Título del video:'); ?></label>
  26.         <p>
  27.           <input type="text" name="video_title[]" id="video_title[]" value="" class="title regular-text" style="width: 98%" />
  28.           <span class="description"><?php _e('Nombre del video.'); ?></span>
  29.         </p>    
  30.         </td>
  31.        
  32.         <td width="50%">        
  33.         <label><?php _e('URL del video:'); ?></label>
  34.         <p>
  35.           <input type="text" name="video_url[]" id="video_url[]" value="" class="url regular-text" style="width: 98%" />
  36.           <span class="description"><?php _e('URL del video de Youtube.'); ?></span>
  37.         </p>
  38.         </td>
  39.        
  40.         <td width="10%" class="commands">
  41.             <a rel="delete" class="button">-</a> <a rel="add" class="button">+</a>
  42.         </td>
  43.        
  44.     </tr>
  45. </table>
  46.  
  47. <table id="adjuntos">
  48.        
  49. </table>
  50.  
  51.  
  52. <script>
  53. (function($)
  54. {
  55.     lines = 0;
  56.    
  57.     function items_init()
  58.     {
  59.         <?php $videos = get_post_meta($post->ID, 'videos', true) ?>
  60.        
  61.         <?php if ( empty($videos) ) : ?>                
  62.         items_add();
  63.         <?php else: ?>
  64.        
  65.         <?php
  66.         // get serialized data
  67.         $videos = unserialize($videos);
  68.        
  69.         // Show stored records
  70.         foreach ($videos as $video) : ?>
  71.         items_add({
  72.             title: '<?php echo $video['title'] ?>',
  73.             url:   '<?php echo $video['url'] ?>'
  74.         });
  75.         <?php endforeach ?>
  76.         <?php endif ?>
  77.        
  78.         // Delete the "-" button in first row
  79.         $('#adjuntos tr:first-child .commands a[rel="delete"]').remove();
  80.     }
  81.    
  82.     function items_add()
  83.     {
  84.         obj = $('#template tr:first-child').clone().appendTo('#adjuntos');
  85.         lines++;
  86.                
  87.         if (arguments.length > 0) {
  88.             options = arguments[0];
  89.            
  90.             $('.title', obj).val( options.title );
  91.             $('.url',   obj).val( options.url );
  92.         }
  93.     }
  94.    
  95.     $('#adjuntos').delegate('.commands a', 'click', function()
  96.     {
  97.         var action = $(this).attr('rel');
  98.         var confirm_delete = true;
  99.        
  100.         // Add action
  101.         if ('add' == action) {
  102.             items_add();
  103.         }
  104.        
  105.         // Delete action
  106.         if ('delete' == action) {
  107.             // La TR en la tabla
  108.             var oTr = $(this).parent().parent();
  109.             var video_name = $('.title', oTr).val();
  110.             var video_url  = $('.url', oTr).val();
  111.            
  112.             if (video_name != '' || video_url != '') {
  113.                 if ( !confirm('Are you sure you want to delete ' + video_name + '?') ) {
  114.                     confirm_delete = false;
  115.                 }
  116.             }
  117.            
  118.             if (confirm_delete) {
  119.                 oTr.remove();
  120.                 lines--;
  121.             }
  122.         }
  123.     });
  124.    
  125.     $(document).ready(function()
  126.     {
  127.         items_init();
  128.     });
  129.    
  130. })(jQuery);
  131.  
  132. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement