WordPress.org

Ready to get started?Download WordPress

Forums

hack needed to make this nice search.php code with sorting filters even better (2 posts)

  1. a4jp.com
    Member
    Posted 2 years ago #

    I've made a PHP search page for a theme that works well and now I want to improve the search filtering/sorting system. Any advice, hacks or tweaks to the code below would be wonderful. *I'm trying to keep away from plugins as my site is starting to slow down a bit from all the other ones I already have installed. This is just a PHP file that has its own filtering. Maybe the code could be used on other pages as well. I hope you find it useful and can help make it even better :) Hack, hack, hack.

    This is the address of my Japanese site if you wanna see it working. agreatdream.com

    I've left in commented out code as it may be useful for some people to much around with.

    <?php get_header()?>
    <div id="content">
    		<!-- Begin Main Content ( left col ) -->
    		<section id="main-content">
    		<div id="archive-title" style="font-size:20px;">
    
        <h2>Search results for "<?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>"'); _e(' &mdash; '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>
    
    		<!--<strong><php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('"'); echo $key; _e('"'); wp_reset_query(); ?></strong>-->
    		</div>
    
        <div style="margin-top:10px; margin-bottom:10px;">
    
        並び順:</label> <strong>新着順</strong> | <strong>人気順</strong> |
    
        <div style="margin-top:10px; margin-bottom:10px;">
        <form role="search" method="get" id="searchform1" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">並び順:date↑</label>
        <input type="text" value="" name="s" id="s" /> in <?php wp_dropdown_categories( 'show_option_all=All Categories&show_count=1&orderby=date&order=ASC' ); ?>
        <input type="submit" id="searchsubmit1" value=" 検索・Search " />
    		</form></div>
    
        <div style="margin-top:10px; margin-bottom:10px;">
        <form role="search" method="get" id="searchform2" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">並び順:date↓</label>
        <input type="text" value="" name="s" id="s" /> in <?php wp_dropdown_categories( 'show_option_all=All Categories&show_count=1&orderby=date&order=DESC' ); ?>
        <input type="submit" id="searchsubmit2" value=" 検索・Search " />
    		</form></div>
    
        <div style="margin-top:10px; margin-bottom:10px;">
        <form role="search" method="get" id="searchform3" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">並び順:title↓</label>
        <input type="text" value="" name="s" id="s" /> in <?php wp_dropdown_categories( 'show_option_all=All Categories&show_count=1&orderby=title&order=DESC' ); ?>
        <input type="submit" id="searchsubmit3" value=" 検索・Search " />
    		</form></div>
    
        <div style="margin-top:10px; margin-bottom:10px;">
        <form role="search" method="get" id="searchform4" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">並び順:名で</label>
        <input type="text" value="" name="s" id="s" /> in <?php wp_dropdown_categories( 'show_option_all=All Categories&show_count=1&orderby=name' ); ?>
        <input type="submit" id="searchsubmit4" value=" 検索・Search " />
    		</form></div>
    
        <div style="margin-top:10px; margin-bottom:10px;">
        <form role="search" method="get" id="searchform5" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">並び順:</label>
    		<input type="text" value="" name="s" id="s" /> in <?php wp_dropdown_categories( 'show_option_all=All Categories&show_count=1' ); ?>
        <input type="submit" id="searchsubmit5" value=" 検索・Search " />
    		</form></div>
        </div>
    
        <hr />
    
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    				<!-- Begin Article -->
    				<article class="post">
    
              <header class="postHeader">
    					  <div style="font-size:18px;margin-top:10px; margin-bottom:10px;"><span style="margin-bottom:7px;"><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></span> by <?php echo get_the_author(); ?></div>
    
                <!--<h3 id="post-<php the_ID(); ?>"><a href="<php the_permalink() ?>" rel="bookmark" title="Permanent Link to <php the_title_attribute(); ?>"><php the_title(); ?></a></h3>-->
    					</header>
    
    					<section class="postText">
    
    					 <!--<php echo '<a href="', get_permalink(), '">';
    					 if (has_post_thumbnail()) {
    					 the_post_thumbnail();
    					 } else {
    					 echo '<img src="', get_bloginfo('template_directory'), '/images/thumb-default.png', '" width="75" height="75" alt="thumbnail" />';
    					 }
    					 echo '</a>'; ?>-->
    
         <?php echo  '<div style="float:right;margin:0 10px 0 10px;"><a href="' . get_permalink() . '" ><img src="' . catch_that_image() . '" width="100" height="100" alt="thumbnail" />'. '</a></div>' ?>
    
    					 <?php the_excerpt()?>
    					</section>
    
              <!--<div style="margin-top:10px; margin-bottom:10px;"><img src="<php bloginfo('template_directory'); ?>/images/16x16-tag-icon.png" alt=""> <php the_category(', ') ?></div>-->
    
              <div style="margin-top:10px; margin-bottom:10px;"><img src="http://agreatdream.com/images/icons/14x14-tag-icon.png" alt=""/> <?php the_category(', ') ?></div>
    
              <div class="date">公開:<?php the_time('M j, Y') ?>&nbsp;&nbsp;更新:<?php the_modified_time('M j, Y') ?><img src="<?php bloginfo('template_directory'); ?>/images/ico_comment.png" alt=""> <?php comments_popup_link('No Comments', '1 Comment ', '% Comments'); ?></span>&nbsp;&nbsp;ID:<?php the_ID();?> </div> <div style="clear:both;"></div>
    
            <div class="sidebadge"></div>
    				</article>
    
            <hr /><br />
    				<!-- End Article -->
    
    			<?php endwhile; ?>
    	<?php else : ?>
    		<p>Sorry, but you are looking for something that isn't here.</p>
    	<?php endif; ?>
    		<?php if (function_exists("emm_paginate")) {
    				emm_paginate();
    			} ?>
    		</section>
    		<!-- End Main Content ( left col ) -->
    </div>
    <?php get_sidebar();?>
    <?php get_footer();?>

    There is also one other thing I would like to make better. If someone clicks on the search area and just pushes enter it doesn't bring up a "Sorry there aren't any results" message. Is there an easy way to include something like that?

    Sorry if the code makes you cringe... I've just learnt from put lots of stuff together :o

    Glen (^-^)

  2. a4jp.com
    Member
    Posted 2 years ago #

    I'm going to work on the code to sort posts and pages now. If someone could help a little it would be wonderful.

    I would love to have a link that sorts the search results. Is it easy to do that?

Topic Closed

This topic has been closed to new replies.

About this Topic