2014-01-28 34 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)。 –

相关问题