ホーム > テンプレート > search.phpと404.phpのいぢくり

2009年04月01日(水曜日) 17時41分

検索ヒット無しニコニコプレス v1.2(春)ですが、条件一致ありの検索結果はテンプレートと揃っているのですが・・・残念な事に一致しなかった場合はベーステーマのままです。
ついでに404.phpも実はベーステーマのままです。

search.phpと404.phpの該当箇所はほぼ同じコードを使ってるので一緒に修正します。


※ニコニコプレス(春) v1.3で盛り込まれました。(2009/04/08追記)

search.phpの修正

まずは・・・searchをした時に条件が一致しなかった場合の表示を・・・。
searchテンプレ デフォルト
う~ん・・・シンプル(笑)
って事でテンプレに併せて修正してみましょう。

ちなみに修正済みの表示は・・・。
searchテンプレ 修正版
結構ええ感じだと思いますよ?(笑)

search.phpの45行目~を入れ替えます。

【入れ替え前】

			<!-- 記事始まり -->
<div id="post-0" class="post no-results not-found">
<h2 class="entry-title"><?php _e( 'Nothing Found', 'sandbox' ) ?></h2>
<div class="entry-content">

<?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'sandbox' ) ?>
</div>
<form id="searchform-no-results" class="blog-search" method="get" action="<?php bloginfo('home') ?>">
<div>
 <input id="s-no-results" name="s" class="text" type="text" value="<?php the_search_query() ?>" size="40" />
 <input class="button" type="submit" value="<?php _e( 'Find', 'sandbox' ) ?>" /></div>
</form></div>
<!-- 記事終わり -->

【入れ替え後】

			<!-- 記事始まり -->
<div id="post-0" class="post no-results not-found">
<h2 class="page-title"><?php _e( '検索結果:', 'sandbox' ) ?></h2>
<div class="entry-content">

<b>検索条件【<?php the_search_query() ?>】に一致する情報は見つかりませんでした。</b>

 ヒント:
 キーワードが正しく入力できているか、誤字がないか確認してみてください。
 検索条件を変えてみてください。
</div>

<h3 class="search"><label for="s"><?php _e( 'サイト内検索', 'sandbox' ) ?></label></h3>
<form id="searchform" name="searchform" class="blog-search" method="get" action="<?php bloginfo('home') ?>">
<table summary="0" class="searchform" border="0" cellpadding="0" cellspacing="4">
<tbody>
<tr>
<td><input id="s" name="s" class="text" value="" size="10" tabindex="1" type="text" /></td>
<td><input src="<?php bloginfo('template_directory') ?>/images/submit_search.png" class="button" value="検索" title="検索" tabindex="2" type="image" /></td>
</tr>
</tbody></table>
</form></div>
<!-- 記事終わり -->

実はここで罠が待ってます。
このままUPすると・・・searchform_bg.png(検索フォームのバックグランド画像)が3個くらい出ます(笑)
実はCSSで背景画像のリピートの仕方を指定していないのです。

回避としてstyle.cssを編集します。
style.cssの902行目の下に【background-repeat: no-repeat;】を追加します。

【追加前】

	background-image:url(images/searchform_bg.png);

【追加後】

background-image:url(images/searchform_bg.png);
background-repeat: no-repeat;

これで修正済みの表示になります。

404.phpの修正

次は・・・404.phpです。
修正前の表示は・・・
ページ無しテンプレ

修正後の表示は・・・
ページ無しテンプレ 修正版
自己満足です(笑)
404.phpの9行目~を入れ替えます。

【入れ替え前】

				<!-- 記事始まり -->
<div id="post-0" class="post error404 not-found">
<h2 class="entry-title"><?php _e( 'Not Found', 'sandbox' ) ?></h2>
<div class="entry-content">

<?php _e( 'Apologies, but we were unable to find what you were looking for. Perhaps  searching will help.', 'sandbox' ) ?>
</div>
<form id="searchform-404" class="blog-search" method="get" action="<?php bloginfo('home') ?>">
<div>
 <input id="s-404" name="s" class="text" type="text" value="<?php the_search_query() ?>" size="40" />
 <input class="button" type="submit" value="<?php _e( 'Find', 'sandbox' ) ?>" /></div>
</form></div>
<!-- 記事終わり -->

【入れ替え後】

			<!-- 記事始まり -->
<div id="post-0" class="post error404 not-found">
<h2 class="page-title"><?php _e( 'ページが見つかりません。', 'sandbox' ) ?></h2>
<div class="entry-content">

<?php _e( '残念ながらお探しのページが見つかりませんでした。
検索ボックスを使えば探し出すことができるかもしれません。', 'sandbox' ) ?>
</div>

<h3 class="search"><label for="s"><?php _e( 'サイト内検索', 'sandbox' ) ?></label></h3>
<form id="searchform" name="searchform" class="blog-search" method="get" action="<?php bloginfo('home') ?>">
<table summary="0" class="searchform" border="0" cellpadding="0" cellspacing="4">
<tbody>
<tr>
<td><input id="s" name="s" class="text" value="" size="10" tabindex="1" type="text" /></td>
<td><input src="<?php bloginfo('template_directory') ?>/images/submit_search.png" class="button" value="検索" title="検索" tabindex="2" type="image" /></td>
</tr>
</tbody></table>
</form></div>
<!-- 記事終わり -->

これでテンプレと揃いました~♪
きっと2010(冬)Verには盛り込まれてるでしょう(笑)

「search.phpと404.phpのいぢくり」 について、Twitterでつぶやく

関連記事

2件のコメント

  • どもです!
    だんだんとボロが出て来てますね・・・w
    404.phpもsearch.phpも製作初期の段階であ~めんどいからいいやと放置されていた箇所なのですww
    次のバージョンでは対応しておきます><w

    投稿日:2009年04月04日(土曜日) 01時48分 | パーマリンク

  • ken c-unknown

    う~ん。そんなにもいぢってませんよ。
    #いぢるところがない(笑)

    テンプレで大きく入れ替えたのってもうないかも?
    あとは日時表示とかを変更したくらいですねぇ・・・。
    ネタ切れです(苦笑)

    >次のバージョンでは対応しておきます><w
    次のバージョンまだぁ~?(笑)

    投稿日:2009年04月04日(土曜日) 14時13分 | パーマリンク