我有一个搜索结果页面,带有一个模板调用内容搜索。php。
基本上,这个文件的作用是在一个人在搜索栏上搜索某个内容后显示结果,我想编辑这个文件的css。
所以我尝试的是,我去函数。php并添加了如下常见代码
functions.php
function content_search_styles() {
    if ( is_page_template( \'content-search.php\' ) ) {
        wp_enqueue_style( \'page-template\', get_stylesheet_directory_uri(). \'/css/content-search.css\' );
    }
}
add_action( \'wp_enqueue_scripts\', \'content_search_styles\' );
content-search.php
<article id="post-<?php the_ID(); ?>" <?php post_class(\'clearfix\'); ?>>
    <h2>Search Results</h2>
    <b>Results as following</b>
    <?php the_title(\'<h1 class="entry-title">\',\'</h1>\' ); ?>
    <?php if( has_post_thumbnail() ): ?>
        <div class="pull-left"><?php the_post_thumbnail(\'thumbnail\'); ?></div>
    <?php endif; ?>
    <small><?php the_category(\' \'); ?> || <?php the_tags(); ?> || <?php edit_post_link(); ?></small>
    <?php the_excerpt(); ?>
    <hr>
</article>
content-search.css
body {
    display:none !important;
}
 CSS不会反映在搜索结果页面上,
请再次建议并感谢您
 
                    最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
                    我打赌你被误解了什么is_page_template 真的很好。抄本:
此模板标记允许您确定是否在页面模板中。您可以选择提供模板名称或模板名称数组,然后检查将特定于该模板。
如果你看看它的代码:
function is_page_template( $template = \'\' ) {
    if ( ! is_singular() ) {
        return false;
    }
 
    $page_template = get_page_template_slug( get_queried_object_id() );
    ...
 。。。你会发现,你不能使用这个函数来定位搜索结果。它不会工作,因为它的目的是检查当前页面是否使用给定的页面模板。另一方面,您想检查给定的文件当前是否正在使用。。。
如果主题编码正确,则应使用is_search() 相反