-
-
Save tommcfarlin/9755d3af436af1ae04a0 to your computer and use it in GitHub Desktop.
[WordPress] An example for using templates, partials, and helper functions in the Dashboard of WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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