2012-12-03 6 views
1

나는 간단한 검색 양식을 통합하고자하는 WordPress 템플릿을 만들고 있습니다. 나는 지난 3 일 동안 이것에 대해 많은 것을 봤고 몇 가지 자습서를 시도했지만 나는 전혀 얻지 못하는 것이 두렵다. 검색을 위해 3 페이지가 있습니다 : search.php, searchform.phpsearchpage.php.Wordpress에서 기본 검색

search.php :

<?php if (have_posts()) : ?> 
… 
<?php while (have_posts()) : the_post(); ?> 
… 
<?php endwhile; else: ?> 
… <p>The key word <strong><?php the_search_query(); ?></strong> is not on this website.</p> 
<?php include (TEMPLATEPATH . "/searchform.php"); ?> 
<?php include (TEMPLATEPATH . "/searchpage.php"); ?> 
<?php endif; ?> 

searchform.php : (page.php에서 적응)

<?php 
$querystring = esc_attr(apply_filters('the_search_query', get_search_query())); 
$searchstring = "Suchbegriff eingeben"; 
if (empty($querystring)) { $querystring = $searchstring; } 
?> 

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> 
<div> 
    <input type="text" name="s" id="s" value="<?php echo $querystring; ?>" 
     onblur="if (this.value == '') { this.value = '<?php echo $searchstring; ?>'; }" 
     onfocus="if (this.value == '<?php echo $searchstring; ?>') { this.value = ''; }" /> 
    <input type="submit" id="searchsubmit" value="Suchen" /> 
</div> 
</form> 

searchpage.php :

모든 튜토리얼이 같은 유사한 코드를 제공하는 많은 읽기
<?php 
/* 
Template Name: Search Page 
*/ 
?> 

<div id="content"> 

<?php if (have_posts()) while (have_posts()) : the_post(); ?> 

    <div class="blogpost"> 
     <h2><?php the_title(); ?></h2> 
     <?php the_content(); ?> 
     <?php $this->posts = $wpdb->get_results($this->request); ?> 
    </div> <!-- end class blogpost --> 
<?php endwhile; ?> 

</div> 
<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

키워드와 일치하는 항목이 없으면 검색이 작동합니다. 그러나 일치가있는 경우에만 … … … … … … …을 출력으로받습니다. 나는 그것이 search.php에서 있어야하는 것을 안다. 그러나 나는 내가 그것을 바꿀 수 있는지 전혀 모른다. 귀하의 조언과 도움을 주셔서 감사합니다, 정말 고마워!

+0

또한 많은 플러그인이 있으며 이러한 3 페이지의 Google 검색 API 중 하나를 사용할 수도 있고 글로벌 검색을 사용할 수도 있습니다. 설치가 매우 쉽습니다. –

답변

2

중요한 파일은 일치하는 결과를 표시하는 search.php 또는 일치하는 항목이없는 경우 실패 메시지입니다. 다음과 같이 시도하십시오 :

<?php 
/** 
* Search results page 
*/ 
?> 
<?php if (have_posts()): ?> 
<h2>Search Results for '<?php echo get_search_query(); ?>'</h2> 
<ol> 
<?php while (have_posts()) : the_post(); ?> 
    <li> 
      <h2><a href="<?php esc_url(the_permalink()); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
      <time datetime="<?php the_time('Y-m-d'); ?>" pubdate><?php the_date(); ?> <?php the_time(); ?></time> <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?> 
      <?php the_content(); ?> 
    </li> 
<?php endwhile; ?> 
</ol> 
<?php else: ?> 
<h2>No results found for '<?php echo get_search_query(); ?>'</h2> 
<?php endif; ?> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 
+0

정말 고맙습니다! – Katy