• Hello! πŸ™‚

    I want to do something, if its a certain template.

    In my case, i want to exclude pages that are “connected” to certain page template(s) from the search. I can already do this for posts, using is_category, cant I?

    So, i need a is_template function, can anybody help me build it?

    Have a nice day!

    – Terje

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    if ( is_page() ) {
    $pageid = (int) $wp_query->post->ID;
    $template = get_post_meta($pageid, '_wp_page_template', true);
    echo '<p>this is the page template' . $template . '</p>';
    $template = get_page_template() ;
    echo '<p>this is the page template' . $template . '</p>';
    }
    ?>
    Thread Starter eagerness

    (@eagerness)

    Thanks for a quick reply πŸ™‚

    However, I realise that this doesent solve my problem entirely.

    I have three domains connected to my wordpress, each serving different content and design/layout depending on which URL you visit. This works fine, until i for example visit domain1.net and want to use the wordpress search. The search result brings up pages and posts linked to the other two domains.

    I took a peak at this tutorial: http://web-kreation.com/index.php/wordpress/wordpress-exclude-pages-from-search-results/ – This guy chooses which categories that are going to be included in the search.

    Based on that, i guess my code would go something in the direction of this:

    function mySearchPostsFilter($query) {
    if (strstr($_SERVER['HTTP_HOST'], "domain1.net") ) and ($query->is_search) {
    $query->set (pages with the domain1-template and category 1,2,3)
    } elseif (strstr($_SERVER['HTTP_HOST'], "domain2.net") ) and ($query->is_search) {
    $query->set (pages with the domain2-template and category 3,4,5)
    } elseif (strstr($_SERVER['HTTP_HOST'], "domain3.net") ) and ($query->is_search) {
    $query->set (pages with the domain2-template and category 4,5,6)
    }
    return $query;
    }
    add_filter('pre_get_posts','mySearchPostsFilter');

    (If the domain im using the search with is this, then include this page template and these categories)

    Again, thanks! πŸ™‚

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘is_template tag’ is closed to new replies.