Skip to content

Instantly share code, notes, and snippets.

<?php elseif(is_404()) : ?>
<h1>404 NOT FOUND ERROR!!</h1>
<p>指定したページが見つかりませんでした。</p>
<?php endif; ?>
<?php endif; ?>
</div><!-- /#content -->
//変更前
<ul>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php endwhile; ?>
</ul>
//変更後
<ul>
<?php while ($r->have_posts()) : $r->the_post(); ?>
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'SearchFilter');
if (isset($_GET['s'])) {
$_GET['s'] = mb_convert_kana($_GET['s'], 's', 'UTF-8');
<?php else: ?>
<?php if (is_search()) : ?>
<?php echo $search_result; ?>
<?php elseif(is_404()) : ?>
<?php endif; ?>
<?php endif; ?>
</div><!-- /#content -->
<div id="content">
<?php if (is_search()) : ?>
<?php $allsearch =& new WP_Query("s=$s&showposts=-1"); ?>
<?php $key = wp_specialchars($s, 1); ?>
<?php $count = $allsearch->post_count; ?>
<?php $search_result = '<p id="search_result">『<span class="search">'.$key.'</span>』で検索した結果、<span class="search">'.$count.'</span>件がヒットしました。</p>'; ?>
<?php endif; ?>
<?php if (have_posts()) : ?>
<?php if (is_search()) : ?>
<?php echo $search_result; ?>
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" value="<?php echo $_GET['s']; ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="" />
</form>
</div><!-- /#content -->
<div id="sidebar">
<ul>
<?php dynamic_sidebar(); ?>
</ul>
</div><!-- /#sidebar -->
</div><!-- /#container -->
register_sidebar();
<?php the_content('続きを読む'); ?>
<?php comments_template(); ?>
</article><!-- /.article -->
<?php if (!is_single()) : ?>
<?php wp_pagenavi(); ?>
<?php endif; ?>