Wordpress Поиск - PullRequest
       9

Wordpress Поиск

2 голосов
/ 17 ноября 2011

есть ли способ просто искать

  • страницы
  • Пользовательские типы
  • Сообщений

В настоящее время я изменяю двадцатьодиннадцать тем.

вот код для search.php :

<?php if ( have_posts() ) : ?>

            <header class="page-header">
                <h1 class="page-title"><?php printf( __( 'Search Results for "%s"', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                <div class="SearchCount"><?php /* Search Count */ 
                $allsearch = &new WP_Query("s=$s&showposts=-1"); 
                //$key = wp_specialchars($s, 1); 
                $count = $allsearch->post_count; _e(''); _e(); 
                    echo $key; _e(); _e(); 
                    echo $count . ' '; _e(''); 
                wp_reset_query(); ?> Saved Results </div>
                <div id="topPagination"><?php twentyeleven_child_content_nav( 'nav-above' ); ?></div>
            </header>

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php
                    /* Include the Post-Format-specific template for the content.
                     * If you want to overload this in a child theme then include a file
                     * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                     */
                    get_template_part( 'content', 'search' );
                ?>

            <?php endwhile; ?>

            <?php twentyeleven_child_content_nav( 'nav-below' ); ?>

        <?php else : ?>

            <article id="post-0" class="post no-results not-found">
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
                </header><!-- .entry-header -->

                <div class="entry-content">
                    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyeleven' ); ?></p>
                    <?php get_search_form(); ?>
                </div><!-- .entry-content -->
            </article><!-- #post-0 -->

        <?php endif; ?>

а вот content-search.php

<h2><a href="<?php the_permalink();?>"> 
        <?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title); ?>
        <?php echo $title; ?>
    </a><br />
<span class="categoryClass"><?php the_category(','); ?></span></h2>

    <?php the_excerpt(); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->

Спасибо

Ответы [ 2 ]

0 голосов
/ 17 ноября 2011

Как я вижу, у вас есть два варианта. Один из них - изменить wp_query, чтобы он возвращал только тот тип, который вам нужен. Второе - поиск по всему, но затем отфильтруйте результаты.

Я полагаю, что вы бы изменили wp_query , используя Параметры типа

$allsearch = &new WP_Query("s=$s&showposts=-1"); //what you currently have
$customsearch = &new WP_Query("post_type=page&posts_per_page =5");

Я полагаю, что вы будете фильтровать пост-поиск

if ( have_posts() ) : while ( have_posts() ) : the_post();
   if (is_page()) {} //do something if page
endwhile;
0 голосов
/ 17 ноября 2011
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...