我正在尝试向WordPress自定义程序功能添加一些控件,但从控件中提取数字值以用于主题时遇到问题。该部分显示在Customizer选项卡中,我可以更改输入,但控件对主题没有影响。
我查阅了使用get\\u theme\\u mod和inline样式来设置div属性的教程,但我还没有弄清楚如何使控件id只返回自定义数值的输入。
$wp_customize->add_section(
"news_portal_grid_section",
array(
\'title\' => esc_html__( \'Grid Style\', \'news-portal-child\' ),
\'panel\' => \'news_portal_grid_settings_panel\',
\'priority\' => 25,
)
);
$wp_customize->add_setting(
\'np_posts_per_page\',
array(
\'default\' => \'6\',
\'sanitize_callback\' => \'sanitize_key\',
)
);
$wp_customize->add_control(new WP_Customize_Control ($wp_customize,
\'np_posts_per_page\',
array(
\'type\' => \'text\',
\'section\' => \'news_portal_grid_section\',
\'settings\' => \'np_posts_per_page\',
\'priority\' => 2,
\'label\' => __( \'Grid Posts\' ),
\'description\' => __( \'This sets the number of posts to display. This must be numeric.\' ),
\'validate\' => \'numeric\',
\'default\' => \'5\',
\'input_attrs\' => array(
\'min\' => 0,
\'max\' => 50,
\'step\' => 1,
),
)) );
我知道这里应该有一个函数/动作挂钩,但WordPress API在如何准确实现这一点上有点模糊。我需要np_post_num()的数字输出作为一个简单的整数或字符串返回,然后可以在$option_pg_number=_________;中声明。
function np_post_num(){
echo get_theme_mod(\'np_posts_per_page\', \'5\');
}
add_action (\'wp_head\', \'np_post_num\');