Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/1-meta-box-tabs.php Secret

Created Oct 23, 2014
Embed
What would you like to do?
[WordPress] An example for using templates, partials, and helper functions in the Dashboard of WordPress.
<?php
/**
* Template for rendering the meta box.
*
* @since 1.0.0
*/
?>
<div id="meta-box-tabbed-navigation">
<h2 class="nav-tab-wrapper current">
<a class="nav-tab nav-tab-active" href="javascript:;">Alpha</a>
<a class="nav-tab" href="javascript:;">Beta</a>
<a class="nav-tab" href="javascript:;">Gamma</a>
</h2>
<?php // More To Come... ?>
</div><!-- #meta-box-tabbed-navigation -->
<?php
/**
* Template for rendering the meta box.
*
* @since 1.0.0
*/
?>
<div id="meta-box-tabbed-navigation">
<h2 class="nav-tab-wrapper current">
<a class="nav-tab nav-tab-active" href="javascript:;">Alpha</a>
<a class="nav-tab" href="javascript:;">Beta</a>
<a class="nav-tab" href="javascript:;">Gamma</a>
</h2>
<?php
// Include the partials for rendering the tabbed content
include_once( 'partials/alpha.php' );
include_once( 'partials/beta.php' );
include_once( 'partials/gamma.php' );
?>
</div><!-- #meta-box-tabbed-navigation -->
<?php
/**
* Partial for rendering the view of the 'Alpha' meta box.
*
* @since 1.0.0
*/
?>
<div id="alpha-container">
<?php $amount = acme_get_financial_post_meta( 'acme_financial_data' ); ?>
<input type="text" id="acme_financial_data" name="acme_financial_data" value="<?php echo $amount; ?>" />
</div><!-- #alpha-container -->
<?php
/**
* Retrieves financial post meta data based on the specified key. Formats the number
* that is stored in the database as an integer as a currency.
*
* @since 1.0.0
*
* @param string $key The meta key from which to pull the data.
* @return string The value of the formatted string.
*/
function acme_get_financial_post_meta( $key ) {
$value = get_post_meta( get_the_ID(), $key, true );
if ( 0 < strlen( trim( $value ) ) ) {
$value = number_format( $value, 2, '.', ',' );
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment