您需要从添加register
操作,然后添加section
, setting
和control
. 请确保将$my\\u主题更改为主题的slug,以便此选项仅显示在主题上。
class SampleAddonCustomizer {
public $my_theme = \'enter-your-theme-slug-here\'; // <- Enter your theme slug here
public function hooks() {
$current_theme = wp_get_theme();
if( $current_theme->template == $this->my_theme ) {
add_action( \'customize_register\', array( $this, \'register\' ), 99 );
}
}
public function register( $wp_customize ) {
$wp_customize->add_section( \'my_custom_section_links\', array(
\'capability\' => \'edit_theme_options\',
\'priority\' => 50,
\'title\' => __( \'Index/Archive\', \'sample-customizer-addon\' )
) );
$wp_customize->add_setting( \'special\', array(
\'capability\' => \'edit_theme_options\',
\'type\' => \'hidden\',
\'autoload\' => false
) );
$wp_customize->add_control( \'special\', array(
\'label\' => \'Links to settings\',
\'description\' => $this->get_links(),
\'section\' => \'my_custom_section_links\',
\'type\' => \'hidden\',
) );
}
public function get_links() {
$links = array(
array(\'url\' => \'http://example.com/\', \'text\' => \'Example\', \'desc\' => \'Just an example\'),
array(\'url\' => \'https://yahoo.com/\', \'text\' => \'Yahoo!\', \'desc\' => \'More entertainment\'),
array(\'url\' => \'https://google.com/\', \'text\' => \'Google\', \'desc\' => \'Just Search\'),
array(\'url\' => \'https://bing.com/\', \'text\' => \'Bing\', \'desc\' => \'Nice pictures\'),
);
$html = \'\';
foreach ($links as $link) {
$html .= \'<p>\'.$link[\'desc\'].\'<br>\'.PHP_EOL;
$html .= sprintf(\'<a href="%s">%s</a>\', $link[\'url\'], $link[\'text\']) . \'<br>\' . PHP_EOL;
$html .= \'</p>\'.PHP_EOL;
}
return $html;
}
}
$sampleAddonCustomizer = new SampleAddonCustomizer();
$sampleAddonCustomizer->hooks();