2017-06-15 76 views
0

我準備了一個產品的自定義帖子。我想包含一個表單,只有幾個篩選器可供搜索。因爲我正在做第一次搜索。我的產品模板是不同的,並希望在頁面或特定div中顯示其結果。這怎麼可能。我有點困惑。以下是我的表單字段。自定義搜索產品定製帖子類型

<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>"> 
      <div class="row"> 
       <div class="col-md-3">Search Keyword:</div> 
       <div class="col-md-3"><input type="text" placeholder="Search Product..."></div> 
       <div class="col-md-2"><input type="submit" id="searchsubmit" value="Searchi"></div> 
      </div> 
      <div class="row"> 
       <lable for="r1"><input type="radio" name="product-filter" id="r1" checked="chcecked"> Any Words</lable> 
       <lable for="r2"><input type="radio" name="product-filter" id="r2"> All Words</lable> 
       <lable for="r3"><input type="radio" name="product-filter" id="r3"> Exact Phrase</lable> 
      </div> 
      <em>Search term must be a minimum of 3 characters and a maximum of 20 characters</em> 
     </form> 

回答

0

通過自定義文章類型蛞蝓在隱藏

桿狀類型名稱:產品

<form role="search" method="get" id="searchform" action="<?php echo esc_url(get_permalink(1)); ?>"> 
       <div class="row"> 
        <div class="col-md-3">Search Keyword:</div> 
        <div class="col-md-3"><input type="text" placeholder="Search Product..."></div> 
        <div class="col-md-2"><input type="submit" id="searchsubmit" value="Searchi"> <input type="hidden" name="post_type" value="products"></div> 
       </div> 
       <div class="row"> 
        <lable for="r1"><input type="radio" name="product-filter" id="r1" checked="chcecked"> Any Words</lable> 
        <lable for="r2"><input type="radio" name="product-filter" id="r2"> All Words</lable> 
        <lable for="r3"><input type="radio" name="product-filter" id="r3"> Exact Phrase</lable> 
       </div> 
       <em>Search term must be a minimum of 3 characters and a maximum of 20 characters</em> 
      </form> 
+0

http://www.graymarkdesigns.com/ssa/product-directory/這是我的頁面...我已將代碼放回到模板文件中。並添加了一個search.php文件。但是當我提交它時,它將我引導到主頁 –

+0

更改操作 <?php echo home_url('/'); ?> to <?php echo get_page_link('product-directory'); ?> –

+0

請檢查更新後的答案 –

0

以下是搜索表單按您的指導下代碼。

<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>"> 
    <label>   
     <span class="screen-reader-text">Search for:</span> 
     <input type="text" placeholder="Search Product..."> 
     <input type="submit" id="searchsubmit" value="Search"> 
     <input type="hidden" name="post_type" value="product"> 
    </label> 
</form> 

以下是形式

<?php if (have_posts()) : ?> 
<h2 class="page-content-title">Search results for: <?php echo get_search_query(); ?></h2> 
<div class="container"> 
<?php while (have_posts()) : the_post(); ?> 
<div class="blog-page-content"> 
<?php if (has_post_thumbnail()) : ?> 
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post_id, 'medium', array('class' => 'img-responsive')); ?></a> 
<?php else : ?> 
<?php endif; ?> 
    <h2><a href="<?php the_permalink(); ?>" class="category-title-link"><?php the_title(); ?></a></h2> 
    <h6 class="article-meta-extra"> 
     <?php if (has_category() && !has_category('Uncategorized')) : ?> 
      <?php the_category(' | '); ?> | 
     <?php else : ?> 
     <?php endif; ?> 
     Posted on <?php the_date(get_option('date_format')); ?> at <?php the_time(get_option('time_format')); ?> by <?php the_author_posts_link(); ?> 
    </h6> 
<?php the_excerpt(); ?> 
<a href="<?php the_permalink(); ?>" class="btn btn-blue btn-block">Read More</a> 
</div><!-- END EACH BLOG--> 
<?php endwhile; ?> 
<?php else : ?> 
<article class="no-posts"><h1>No posts were found.</h1></article> 
<?php endif; ?> 
</div> 
<div class="article-nav clearfix"> 
<p class="article-nav-next pull-right"><?php previous_posts_link(__('Newer Posts »')); ?></p> 
<p class="article-nav-prev pull-left"><?php next_posts_link(__('« Older Posts')); ?></p> 
</div> 

下方的搜索結果的問題是,它始終顯示的結果。我的自定義帖子名稱是沒有s的'產品'。

+0

什麼是您的自定義帖子類型?產品或產品?以及「產品目錄」頁面的頁面標識是什麼。轉到admin-> pages->編輯「product-directory」並複製瀏覽器url的頁面id。沒有S的 –

+0

產品是我的自定義帖子 –

+0

好的。什麼是你的「產品目錄」頁面ID? –

相關問題