2012年01月23日 WordPress

1.まずは検索フォームを設置します

searchform.php

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>" >
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" size="30" />
<?php wp_dropdown_categories('show_option_all='.__('ALL').'&hide_empty=1');?>
<input type="submit" id="submit" value="検索">
</form>

2.次に検索結果を取得、表示させる

search.phpの検索結果を表示させる部分

<h2>検索結果:<?php the_search_query(); ?></h2>
    <?php     
    global $query_string;
    query_posts($query_string . "&post_type=post&showposts=20");
    ?>   



    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>    <!-- キーワードに合った記事を表示させる処理 -->

<div class="search_result">
           <h3> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="post_meta">
<?php the_time('Y年n月j日'); ?> | カテゴリ: <?php the_category(' '); ?>
</div>
                    <p><?php echo mb_substr(get_the_excerpt(), 0, 100); ?></p>
 <div class="more_button"><a href="<?php the_permalink(); ?>">この記事を読む</a></div>
</div>
    <?php endwhile; ?>
 
    <?php else: ?>    <!--  キーワードが見つからないときの処理 -->
            <p>キーワードはみつかりません。</p>


    <?php endif; ?>

この投稿へのコメント

コメントはまだありません。

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます。
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA


ピックアップ記事

wordpress 現在のuser_idやdisplay_nameを取得

2020年01月14日 WordPress
現在のuser_idを取得 [php] $user_id = get_current_user_id();[/php] 現在のdisplay_nameを取得 [php]$user = wp_get_current_user(); $display_name = $user->display_name;[/php]
「wordpress 現在のuser_idやdisplay_nameを取得」をはてなブックマークに追加

WordPressでindex.htmlとindex.phpを混在させる

2011年06月14日 WordPress
なんともない話題ではありますが、既存のサイトを公開したまま、index.phpの方で、WordPressを入れて、リニューアルをと思ってたんですが、index.phpもindex.htmlもWordPressのホームディレクトリにリダイレクトされてるようです。 どうしたもんかと思ってたら、簡単に解決する方法がありました。 wp-include内のcanonical.phpファイルを開き、270行…
「WordPressでindex.htmlとindex.phpを混在させる」をはてなブックマークに追加

未解決 twitter関連のOAuth認証が通らない 

2011年05月27日 WordPress
WP to Twitterなど、twitter関連のOAuth認証が通らない 原因は不明だけど、サーバのcURLやら外部向けのHTTPS通信が許可されてないやら、その辺っぽい。 ちなみに現在使っているのは、お名前.comの共用サーバです。 VPSの方も契約してるんで、そっちに移行した方が早いかも。 http://bono.s201.xrea.com/pib/wpm/?p=32 twitt…
「未解決 twitter関連のOAuth認証が通らない 」をはてなブックマークに追加

記事のタイトルを表示

2011年11月24日 WordPress
[php] <?php the_title(); ?> [/php]
「記事のタイトルを表示」をはてなブックマークに追加

WordPressサイト全体に認証をかける

2011年11月30日 WordPress
プラグインダウンロード 以下のサイト内から「Angsuman’s Authenticated WordPress Plugin」をダウンロードします。 Angsuman’s Authenticated WordPress Plugin プラグイン編集 プラグインの内容が古くなっていて、最新のWordPressの認証に対応していないので、以下のように書き換えます。 ac_authenti…
「WordPressサイト全体に認証をかける」をはてなブックマークに追加
© graffiti on the web . All rights reserved. WordPress Theme by comfy