$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>templates - Edit css for search results page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

templates - Edit css for search results page

matteradmin9PV0评论

I have a search results page with a template call content-search.php.

Basically what this file does is to display the results after a person searches something on the search bar, and i would like to edit the css of this file.

So what I attempted was , i went to functions.php and added the usual code like this

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;
}

The CSS does not reflect on the search results page,

Please advise and thank you very much once again

I have a search results page with a template call content-search.php.

Basically what this file does is to display the results after a person searches something on the search bar, and i would like to edit the css of this file.

So what I attempted was , i went to functions.php and added the usual code like this

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;
}

The CSS does not reflect on the search results page,

Please advise and thank you very much once again

Share Improve this question edited Feb 13, 2019 at 5:00 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Feb 12, 2019 at 16:30 deshdesh 1372 silver badges10 bronze badges 1
  • Is the content-search.php file placed directly in the root of the theme? if not you need to specify the relative path to the root of the theme – Fabrizio Mele Commented Feb 12, 2019 at 16:39
Add a comment  | 

1 Answer 1

Reset to default -1

I bet that you’re misunderstood what is_page_template is really doing. From Codex:

This template tag allows you to determine if you are in a page template. You can optionally provide a template name or array of template names and then the check will be specific to that template.

And if you’ll take a look at it’s code:

function is_page_template( $template = '' ) {
    if ( ! is_singular() ) {
        return false;
    }
 
    $page_template = get_page_template_slug( get_queried_object_id() );
    ...

... you’ll get, that you can’t use this function to target search results. It won’t work, because it’s meant to check if current page uses given page template. On the other hand you want to check if given file is currently used...

If your theme is coded correctly, then you should use is_search() instead.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far