Add The getCustomField() Function to Functions.php
Open up your theme’s functions.php file. If you don’t have one, create it. Add the following PHP function to the file.
// Get Custom Field Template Values function getCustomField($theField) { global $post; $block = get_post_meta($post->ID, $theField); if($block){ foreach(($block) as $blocks) { echo $blocks; } } }
Load The Content into Your Theme
Next we need to take the content created by these new fields and add it to our template. To do this we’ll need some basic PHP.<div id="block-1" class="content-box">
<h2>Block #1</h2>
<div class="entry">
<?php getCustomField('Block #1'); ?>
</div>
</div>
<div id="block-2" class="content-box">
<h2>Block #2</h2>
<div class="entry">
<?php getCustomField('Block #2'); ?>
</div>
</div>
沒有留言:
張貼留言