So I have a video site based on wordpress - The search page currently shows post in date order but I want the users to have an option to sort the results by different options for example sort by views, duration or even sort by date but they can have an option to select the sorting when they see the search result. here is the current code

<?php get_header(); ?>   <div id="main">

  <?php include(TEMPLATEPATH.'/home_sidebar.php') ?>

  <div id="content">
    <div class="mozaique"><h2 class="titlebar">Search result for <?php echo $_GET['s'] ?></h2>
" rel="bookmark" title="">
            <img src="<?php echo $thumb; ?>" id="pic_<?=get_the_ID();?>" <? if (strpos($thumb,'xvideos.com')) { $thumbbaseurl=explode('.',$thumb); ?> onMouseOver="startThumbSlide('<?=get_the_ID();?>', '<?=$thumbbaseurl[3];?>', '<? echo $thumbbaseurl[0].".".$thumbbaseurl[1].".".$thumbbaseurl[2].".";?>')"  onMouseOut="stopThumbSlide();" <?}?>alt="<?php the_title_attribute(); ?>" /> 

          <p><a href="<?php the_permalink() ?>"><?php echo tube_get_limited_string($post->post_title,36); ?></a></p>

          <p class="metadata">                <span class="bg">                  <span class="duration"><?php $duration = tube_getcustomfield('duration',get_the_ID()); if(empty($duration)) $duration = ' '; echo $duration; ?></span><?php  edit_post_link('Edit this entry','','.'); ?> <?php if (is_admin_bar_showing()) { echo '<a href="'.get_delete_post_link().'">Delete</a>';}?>                                </span>              </p>

                        <?php endwhile; wp_reset_query(); ?>
                        $next_page = get_next_posts_link('Previous'); 
                        $prev_pages = get_previous_posts_link('Next');
                        if(!empty($next_page) || !empty($prev_pages)) :
                        <!-- navigation -->
                        <div class="clear"></div>
                        <div class="navigation">
                            <?php if(!function_exists('wp_pagenavi')) : ?>
                            <div class="alignleft"><?php echo $next_page; ?></div>
                            <div class="alignright"><?php echo $prev_pages; ?></div>
                            <?php else : wp_pagenavi(); endif; ?>
                        <!-- /navigation -->
                        <?php endif; ?>
                    else :
                        ?><p class="nopost">Sorry, but you are looking for something that isn't here.</p><?php
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Below Content') ) : ?>
                    <?php endif ?>              </div> <!-- .mozaique -->

  </div> <!-- #content -->

Solved by a dropdown -

    <h1 class="titlebar"><div id="sortby"> SORT BY:; 

Sort by Newest Oldest Most Viewed Relevance Duration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.