2012-06-03 60 views
0

我的当前PHP代码正在工作,并按我希望的样子使用我的“主题选项”页面(位于WP API外观菜单下)。将CSS应用于“主题选项”页面仅在Wordpress中

CSS样式表也适用于WP仪表板中的每个其他菜单(例如影响“设置>常规选项”)页面。我该如何才能将样式表应用到我的“主题选项”页面,而不是篡改其他任何东西?

我的样式表被命名为'theme-options.css',它位于一个名为“include”> include/theme-options.css的文件夹中。下面的代码被放置在“theme-options.php”页面。

<?php 
// Add our CSS Styling 
add_action('admin_menu', 'admin_enqueue_scripts'); 
function admin_enqueue_scripts() { 
    wp_enqueue_style('theme-options', get_template_directory_uri() . '/include/theme-options.css'); 
    wp_enqueue_script('theme-options', get_template_directory_uri() . '/include/theme-options.js'); 
} 

回答

4

我分别从我的网页(略高于该功能)的积木放置CSS & JS文件。代码现在里面我的页面构建函数,我现在正在得到我以后的结果。

以前:

... 
// Add our CSS Styling 
function theme_admin_enqueue_scripts($hook_suffix) { 
    wp_enqueue_style('theme-options', get_template_directory_uri() . '/include/theme-options.css', false, '1.0'); 
    wp_enqueue_script('theme-options', get_template_directory_uri() . '/include/theme-options.js', array('jquery'), '1.0');  

// Build our Page 
function build_options_page() { 

ob_start(); ?> 
    <div class="wrap"> 
     <?php screen_icon();?> 

     <h2>Theme Options</h2> 

     <form method="post" action="options.php" enctype="multipart/form-data"> 

     ... 
     ... 

解决方案:

// Build our Page 
function build_options_page() { 

// Add our CSS Styling 
wp_enqueue_style('theme-options', get_template_directory_uri() . '/include/theme-options.css'); 
wp_enqueue_script('theme-options', get_template_directory_uri() . '/include/theme-options.js'); 

ob_start(); ?> 
    <div class="wrap"> 
     <?php screen_icon();?> 

     <h2>Theme Options</h2> 

     <form method="post" action="options.php" enctype="multipart/form-data"> 

     ... 
     ... 
+0

'is_page'不适合我,这种方法确实如此。 – gurung

1

你只能如果当前页面是你的特殊的页面由checking the page前添加CSS文件,如:

if (is_page('Theme Options')) { // check post_title, post_name or ID here 
    add_action('admin_menu', 'admin_enqueue_scripts'); 
} 

=== UPDATE ===

也许是BETT呃检查的功能:

<?php 
// Add our CSS Styling 
add_action('admin_menu', 'admin_enqueue_scripts'); 
function admin_enqueue_scripts() { 
    if (is_page('Theme Options')) { // check post_title, post_name or ID here 
     wp_enqueue_style('theme-options', get_template_directory_uri() . '/include/theme-options.css'); 
    } 
    wp_enqueue_script('theme-options', get_template_directory_uri() . '/include/theme-options.js'); 
} 
+0

感谢您的快速响应,并从,我发现我的解决方案。 – user1752759

相关问题