使用自定义元框,我将如何在页面中显示背景图像(如果没有链接图像,则显示颜色)。
要显示数据的页面的代码。我想将背景色/图像应用于节id=“刊头”。
<?php if (get_post_meta($post->ID, \'_sqcmb_masthead_select\', true)) { ?>
</div><!--end #container .row (from header)-->
<section id="masthead">
<div class="row">
<div class="large-9 large-centered columns">
<?php
$content = get_post_meta( $post->ID, \'_sqcmb_masthead_content\', true );
echo do_shortcode( $content );
?>
</div><!-- .large- centered columns -->
</div><!-- .row -->
</section><!-- #masthead -->
<!--restart #container .row (from header)--><div id="content" class="row">
<? } else { ?>
<?php } ?>
自定义元框的代码。
/*Metaboxes for masthead section */
$meta_boxes[] = array(
\'id\' => \'masthead-options\',
\'title\' => \'Masthead Options\',
\'pages\' => array( \'page\' ), // Show on Pages
\'context\' => \'normal\',
\'priority\' => \'high\',
\'show_names\' => true, // Show field names on the left
\'fields\' => array(
array(
\'name\' => \'Display Masthead\',
\'desc\' => \'Check this box id you want to display the Masthead Section.\',
\'id\' => $prefix . \'masthead_select\',
\'type\' => \'checkbox\',
),
array(
\'name\' => \'Masthead Content\',
\'desc\' => \'Enter the content of the masthead section here. You can insert media, shortcodes, etc.\',
\'id\' => $prefix . \'masthead_content\',
\'type\' => \'wysiwyg\',
\'options\' => array( \'textarea_rows\' => 5, ),
),
array(
\'name\' => \'Background Color\',
\'desc\' => \'Choose a background color.\',
\'id\' => $prefix . \'masthead_bg_color\',
\'type\' => \'colorpicker\',
\'std\' => \'#ffffff\'
),
array(
\'name\' => \'Background Image\',
\'desc\' => \'Upload an image as the background. This will override the Background Color. (optional)\',
\'id\' => $prefix . \'masthead_bg_image\',
\'type\' => \'file\',
),
),
);