dragunoff

wpquestions.com, ID = 2855

Aug 18th, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2. /**
  3.  * functions.php
  4.  *
  5.  * this code creates the metabox object
  6.  */
  7.  
  8. // include the class in your theme or plugin
  9. include_once 'WPAlchemy/MetaBox.php';
  10.  
  11. // include css to help style our custom meta boxes ( if necessary - uncomment and fix paths )
  12. // if ( is_admin() ) { wp_enqueue_style( 'custom_meta_css', get_bloginfo( 'stylesheet_directory' ) . '/custom/meta.css' ); }
  13.  
  14. // create the metabox object
  15. $custom_metabox = new WPAlchemy_MetaBox( array(
  16.     'id' => '_mcms_testimonial', // prefixing with an underscore will hide it from the 'Custom Fields' box
  17.     'title' => 'Testimonials', // title of the box
  18.     'types' => array( 'custom_post_type_slug' ), // post types
  19.     'template' => STYLESHEETPATH . '/custom/meta.php' // the actual metabox ( fix paths if necessary )
  20.      )
  21.  );
  22. ?>
  23.  
  24.  
  25. <?php
  26. /**
  27.  * meta.php
  28.  *
  29.  * this defines the guts of the metabox
  30.  * the HTML/CSS is up to you
  31.  */
  32. ?>
  33. <div class="mcms_optinpage">
  34.  
  35.     <?php while( $mb->have_fields_and_multi( 'testimonials' ) ): ?>
  36.     <?php $mb->the_group_open(); ?>
  37.      
  38.         <?php $mb->the_field( 'name' ); ?>
  39.         <label>Testimonial Name</label><div class='description'>Enter the name of your testimonial.</div>
  40.         <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" /></p>
  41.      
  42.         <?php $mb->the_field( 'content' ); ?>
  43.         <label>The Testimonial</label><div class='description'>Enter the testimonial which your prospect gave you.</div>
  44.         <p><textarea type="text" name="<?php $mb->the_name(); ?>"><?php $mb->the_value(); ?></textarea></p>
  45.      
  46.         <?php $mb->the_field( 'audio' ); ?>
  47.         <label>OPTIONIAL Testimonial Audio Button</label><div class='description'>Enter the URL to the mp3 of your testimonial.</div>
  48.         <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" /></p>
  49.      
  50.      
  51.     <?php $mb->the_group_close(); ?>
  52.     <?php endwhile; ?>
  53.      
  54.     <p>
  55.         <a href="#" class="docopy-testimonials button">Add Testimonial</a>
  56.     </p>
  57.    
  58. </div>
  59.  
  60.  
  61. <?php
  62. /**
  63.  * custom-post-type-template.php
  64.  *
  65.  * use this to retrieve the meta values in the template ( inside a WP loop )
  66.  * the HTML is up to you, this will simply echo the values out
  67.  */
  68.  
  69. // WP Alchemy metabox
  70. global $custom_metabox;
  71.  
  72. // get the meta data for the current post
  73. $custom_metabox->the_meta();
  74.  
  75. // loop a set of field groups
  76. while( $custom_metabox->have_fields( 'testimonials' ) )
  77. { ?>
  78.  
  79.     <p>
  80.         <?php $custom_metabox->the_value( 'name' ); ?>
  81.     </p>
  82.  
  83.     <p>
  84.         <?php $custom_metabox->the_value( 'content' ); ?>
  85.     </p>
  86.  
  87.     <?php // checking if a value exists
  88.     if ( $custom_metabox->get_the_value( 'audio' ) ) { ?>
  89.     <p>
  90.         <?php $custom_metabox->the_value( 'audio' ); ?>
  91.     </p>
  92.     <?php } ?>
  93.    
  94. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment