这里是PHP新手,我的函数中有这个。php
function mcs_social($wp_customize){
$wp_customize->add_section(\'mcs_social_handle\', array(
\'title\' => __(\'Social Network Handles\', \'mcs\'),
\'description\' => \'i.e., Acme Company\\\'s Facebook is https://facebook.com/acmecompany then enter "acmecompany"\',
\'priority\' => 70,
));
// =============================
// = Facebook =
// =============================
$wp_customize->add_setting(\'mcs_fb_op\', array(
\'default\' => \'\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'option\',
));
$wp_customize->add_control(\'mcs_fb\', array(
\'label\' => __(\'Facebook Handle\', \'mcs\'),
\'section\' => \'mcs_social_handle\',
\'settings\' => \'mcs_fb_op\',
));
// =============================
// = Twitter =
// =============================
$wp_customize->add_setting(\'mcs_tw_op\', array(
\'default\' => \'\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'option\',
));
$wp_customize->add_control(\'mcs_tw\', array(
\'label\' => __(\'Twitter Handle\', \'mcs\'),
\'section\' => \'mcs_social_handle\',
\'settings\' => \'mcs_tw_op\',
));
// =============================
// = RSS =
// =============================
$wp_customize->add_setting(\'mcs_rs_op\', array(
\'default\' => \'rss2_url\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'option\',
));
$wp_customize->add_control( \'mcs_rs\', array(
\'settings\' => \'mcs_rs_op\',
\'label\' => \'RSS Feed\',
\'section\' => \'mcs_social_handle\',
\'type\' => \'select\',
\'choices\' => array(
\'rdf_url\' => \'RDF/RSS 1.0 feed\',
\'rss2_url\' => \'RSS 2.0 feed\',
\'atom_url\' => \'Atom feed\',
),
));
}
//add
add_action( \'customize_register\', \'mcs_social\' );
正如你所看到的,这是
WordPress Codex.
现在,这非常有效。当我进入外观->自定义时,我会看到社交手柄部分,可以添加和保存到文本框,并从选择中进行选择。
我现在的问题是,我似乎无法获取要在模板中使用的值。我还有其他自定义程序部分,在自定义程序中有1个设置(即徽标图像),它们工作正常,但当我对“社交”设置使用相同的get\\u theme\\u mod()时,什么都不会出现。
<div class="blue-social-box">
<h5>Follow us on:</h5>
<ul>
<?php if ( get_theme_mod( \'mcs_fb_op\' ) ) : ?>
<li>
<figure><a href="https://www.facebook.com/<?php echo esc_url( get_theme_mod( \'mcs_fb_op\' ) ); ?>" target="_blank"><img src="<?php echo $fbImg; ?>" /></a></figure>
<label><a href="https://www.facebook.com/<?php echo esc_url( get_theme_mod( \'mcs_fb_op\' ) ); ?>" target="_blank">Facebook</a></label>
</li>
<?php elseif ( get_theme_mod( \'mcs_fb_op\' ) ) : ?>
<li>
<figure><a href="https://www.twitter.com/<?php echo esc_url( get_theme_mod( \'mcs_tw_op\' ) ); ?>" target="_blank"><img src="<?php echo $twImg; ?>" /></a></figure>
<label><a href="https://www.twitter.com/<?php echo esc_url( get_theme_mod( \'mcs_tw_op\' ) ); ?>" target="_blank">Twitter</a></label>
</li>
<?php
elseif ( get_theme_mod( \'mcs_rs_op\' ) ) :
$rssType = esc_url(get_theme_mod(\'mcs_rs_op\'));
?>
<li>
<figure><a href="<?php bloginfo($rssType); ?>" target="_blank"><img src="<?php echo $rsImg; ?>" /></a></figure>
<label><a href="<?php bloginfo($rssType); ?>" target="_blank">RSS Feed</a></label>
</li>
<?php else : //Nothing ?>
<?php endif; ?>
</ul>
</div>
我在文档中没有发现任何有用的东西,那么获取这些值的正确方法是什么呢?