2014-01-28 30 views
0

我有一個響應式Wordpress主題來自「Elegant Themes」,效果很好,但是有一個頁面我希望是無響應的。我創建了一個能夠成功呈現網站無響應的樣式表,但我只想讓它在使用特定頁面模板時使用上述樣式表。當使用獨特的Wordpress頁面模板時,使用functions.php文件來調用特定的樣式表

我確定邏輯可能是執行它的functions.php文件,而且我可能需要使用「wp_enqueue_style」,但我似乎無法破解它。這就是我現在所擁有的(我除了低於加載主樣式表評論:

function et_nexus_load_scripts_styles(){ 
global $wp_styles; 

$template_dir = get_template_directory_uri(); 

if (is_singular() && comments_open() && get_option('thread_comments')) 
    wp_enqueue_script('comment-reply'); 

wp_enqueue_script('superfish', $template_dir . '/js/superfish.js', array('jquery'), '1.0', true); 

wp_enqueue_script('nexus-custom-script', $template_dir . '/js/custom.js', array('jquery'), '1.0', true); 
wp_localize_script('nexus-custom-script', 'et_custom', array(
    'mobile_nav_text' => esc_html__('Navigation Menu', 'Nexus'), 
    'ajaxurl'   => admin_url('admin-ajax.php'), 
    'et_hb_nonce'  => wp_create_nonce('et_hb_nonce'), 
)); 

$et_gf_enqueue_fonts = array(); 
$et_gf_heading_font = sanitize_text_field(et_get_option('heading_font', 'none')); 
$et_gf_body_font = sanitize_text_field(et_get_option('body_font', 'none')); 

if ('none' != $et_gf_heading_font) $et_gf_enqueue_fonts[] = $et_gf_heading_font; 
if ('none' != $et_gf_body_font) $et_gf_enqueue_fonts[] = $et_gf_body_font; 

if (! empty($et_gf_enqueue_fonts)) et_gf_enqueue_fonts($et_gf_enqueue_fonts); 

/* 
* Loads the main stylesheet. 
*/ 

if (is_page_template('custom-pagetemplate.php')) { 
    wp_register_style(‘custom-style’, get_stylesheet_directory_uri() . ‘/customstyles.css’ ); 
    wp_enqueue_style(‘custom-style’); 
} else { 
    wp_enqueue_style('nexus-style', get_stylesheet_uri()); 
}  
} 
add_action('wp_enqueue_scripts', 'et_nexus_load_scripts_styles'); 

從我可以告訴,我有我的條件設置使用is_page_template正確,但絕對沒有使用右側樣式表加載頁面

注意:我將這個問題發佈到Elegant Themes的定製支持板上,主持人說我想要做的事情是可能的,但是它需要一個級別的定製需要我僱傭第三方開發者。

話雖如此,如果我在這裏錯過了很多東西,需要拿起一本PHP書(我對PHP知之甚少),或者掏出一些現金聘請某人完成這些工作,請不要猶豫讓我平靜下來。否則,任何輸入是非常讚賞。

謝謝!

回答

2

對不起跳槍,並回答我的問題迅速,但我得到了它的工作使用下面的代碼:

if (is_page_template('custom-pagetemplate.php')) { 
wp_enqueue_style('custom-style', get_template_directory_uri() . '/customstyle.css'); 
} else { 
wp_enqueue_style('nexus-style', get_stylesheet_uri()); 
}  
} 
add_action('wp_enqueue_scripts', 'et_nexus_load_scripts_styles'); 

我的主要問題是我使用的是get_stylesheet_directory_uri()而不是get_template_directory_uri

這篇文章幫了我很多:How to enqueue a custom stylesheet via functions.php in WordPress

謝謝!

2

你可以做一些類似這樣的東西:

if(is_page($page)) { 
    // Load non responsive css 
    } 
    else { 
    // load normal css 
    } 

http://codex.wordpress.org/Function_Reference/is_page

+0

感謝您的快速回復,但我已經在原始示例中使用了該代碼。另外,您的代碼引用一個頁面,我的目標是將樣式表加載到特定的頁面模板上(使用is_page_template)。 –

相關問題