【WordPress】検索フォーム
検索フォームを使うトキ、searchform.php又は、検索フォームを入れたい場所に書きます。
それから検索結果を表示させるコードの覚書です。
検索フォームを入れたい場所(searchform.php,index.phpなど)
<form action="/" method="get">
<fieldset>
<label for="search">Search in <?php bloginfo( 'name' ); ?></label>
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />
<input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</fieldset> </form>
<form action="/" method="get">
<fieldset>
<label for="search">Search in <?php bloginfo( 'name' ); ?></label>
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />
<input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</fieldset> </form>
上記のように入力フォームの名前はaにして、labelを含ませる。
検索結果をindex.phpなどで表示させるときは
検索結果をindex.phpなどで表示させるときは
<?php if (is_archive()): ?>
<?php
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
//タグ検索した時
<?php if(is_tag()): ?>
<p>タグ "<?php single_tag_title(); ?>":<?php echo $total_results; ?>件</p>
//カテゴリー検索した時
<?php elseif(is_category()): ?>
<p>カテゴリー "<?php single_cat_title(); ?>":<?php echo $total_results; ?>件</p>
<?php endif; ?>
//検索フォームから検索した時
<?php elseif (is_search()): ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<p>"<?php the_search_query(); ?>" で検索した結果:<?php echo $total_results; ?>件</p>
<?php endif; ?>
$total_results = $wp_query->found_posts;
?>
//タグ検索した時
<?php if(is_tag()): ?>
<p>タグ "<?php single_tag_title(); ?>":<?php echo $total_results; ?>件</p>
//カテゴリー検索した時
<?php elseif(is_category()): ?>
<p>カテゴリー "<?php single_cat_title(); ?>":<?php echo $total_results; ?>件</p>
<?php endif; ?>
//検索フォームから検索した時
<?php elseif (is_search()): ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<p>"<?php the_search_query(); ?>" で検索した結果:<?php echo $total_results; ?>件</p>
<?php endif; ?>
もし、間違っていたなどありましたら教えて下さいm(_ _)m
« WordPress ブログで『続きをみる』 | トップページ | 【WordPress】前の記事・次の記事 »
「WordPress」カテゴリの記事
- Blogの更新をfacebookやTwitterに自動更新(2013.01.26)
- 【WordPress】前の記事・次の記事(2012.12.30)
- 【WordPress】検索フォーム(2012.12.27)
- WordPress ブログで『続きをみる』(2012.12.22)
コメント
この記事へのコメントは終了しました。
I gotta bookmark this site it seems extremely helpful extremely helpful
投稿: louis vuitton purses | 2012/12/27 21時47分