2012-07-12 96 views
0

我創建了一個搜索表單和search.php文件來顯示結果。唯一的是,我想過濾包括標籤,而不是內容和標題。這個過程有沒有wordpress功能?如何按類別和標籤過濾WordPress結果?

搜索表單代碼:

<?php if(is_category(array('general-support','activities','discount-cards','equipment','financial','holidays','medical','respite')) || is_single()){?> 

<div style="width:auto; margin:0px 40px 0px 20px;"> 

    <form role="search" action="<?php bloginfo('siteurl');?>" style="margin:0px; padding:0px;"> 

     <div> 
      <h2>Search for</h2> 
      <div><input type="text" name="s" id="s" style="width:100%; padding:5px; border:1px solid #ccc; box-shadow:inset 1px 1px 1px #f0f0f0;" /></div> 
      <div><input type="hidden" value="14,16,21,18,20,15,22,19,17" name="cat" id="scat" /></div> 
     </div> 

    </form> 

</div> 

<?php } ?> 

的search.php

<?php query_posts($query_string . '&showposts=10'); ?> 

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

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> 

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


<div <?php post_class() ?> id="post-<?php the_ID(); ?>"> 
    <div class="entry"> 

     <!--start.entry-wrapper--> 
     <div class="entry-wrapper"> 

      <!--start.post-thumbnail--> 

      <?php if(has_post_thumbnail()){?> 

      <div class="post-thumbnail-wrapper"> 
       <a href="<?php the_permalink();?>"> 
        <?php the_post_thumbnail('category-thumb'); ?> 
       </a> 
      </div> 

      <?php } ?> 

      <!--end.post-thumbnail--> 

      <!--start.post-entry---> 
      <div class="post-enry-wrapper"> 
       <h2><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'udesign'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
       <div class="postmetadata"> 
        <?php the_content();?>    
       </div> 
      </div> 

      <!--end.post-entry--> 
      <div class="clear"></div> 
     </div> 
     <!--end.entry-wrapper--> 

    </div> 

    <?php if(!is_category() && !is_single()){?> 

    <div><?php if(function_exists('kc_add_social_share')) kc_add_social_share(); ?></div> 

    <?php }?> 

</div> 
<div class="addGap"></div> 
<?php endwhile; ?> 

<div class="clear"></div> 

<?php  // Pagination 
if(function_exists('wp_pagenavi')) : 
    wp_pagenavi(); 
else : ?> 

    <div class="navigation"> 
    <div class="alignleft"><?php previous_posts_link() ?></div> 
    <div class="alignright"><?php next_posts_link() ?></div> 
</div> 

<?php  endif; ?> 

請指教,我不喜歡使用任何插件。

回答

相關問題