The Easiest Way to Save and Share Code Snippets on the web

Untitled

php

last edit: Oct, 7th 2010 | jump to bottom

<?php
 
	$sorts = array('Title', 'Launch Date', 'Comments', 'Submission Order', 'For Sale');
	echo '<li><span class="by_title"></span>
		<ul class="orderby" name="orderby">';
	foreach($sorts as $sort):
		echo '<li title="'.ucwords($sort).'" rel="'.preg_replace('/W/', '-', $sort).'">'.ucwords($sort).'</li>';
	endforeach;
	echo ' </ul></li>';
 
	$dirs = array('asc' => 'Ascending' , 'desc' => 'Descending');
	echo '<li><span class="order_title"></span>
		<ul class="order" name="order">';
	foreach($dirs as $dir => $title):
		echo '<li title="'.$title.'" rel="'.$dir.'">'.$title.'</li>';
	endforeach;
	echo ' </ul></li>';									
	global $query_string;
 
	if($_GET['by'] != ''):
		switch ($_GET['by']):
			case 'Title':
				$query_string .= "&orderby=title";
				query_posts($query_string);
				break;
			case 'Launch-Date':
				$query_string .= "&orderby=meta_value&meta_key=launch_date_new";
				query_posts($query_string);
				break;
			case 'Comments':
				$query_string .= "&orderby=comments";
				query_posts($query_string);
				break;
			case 'Submission-Order':
				$query_string .= "&orderby=date";
				query_posts($query_string);
				break;
			case 'For-Sale':
				$query_string  .= "&orderby=meta_value&meta_key=Purchasable&meta_value=1";
				query_posts($query_string);
				break;
			default:
				return true;
				break;
		endswitch;
	endif;
	if($_GET['dir'] != ''):
		if($_GET['dir'] == 'asc'):
			$query_string .= "&order=ASC";
			query_posts($query_string);
		elseif($_GET['dir'] == 'desc'):
			$query_string .= "&order=DESC";
			query_posts($query_string);
		endif;
	endif;
 ?>
</ul>
</div>
<script type="text/javascript">
	jQuery(document).ready(function($){
		<?php if( $_GET['by'] != ''): ?>
			$('.by_title').html( $('.orderby li[rel="<?php echo $_GET['by'] ?>"]').attr('title') );
		<?php else: ?>
			$('.by_title').html( $('.orderby li:first').attr('title') );
		<?php endif; ?>
		<?php if( $_GET['dir'] != ''): ?>
			$('.order_title').html( $('.order li[rel="<?php echo $_GET['dir'] ?>"]').attr('title') );
		<?php else: ?>
			$('.order_title').html($('.order li:first').attr('title'));
		<?php endif; ?>
		$('.orderby li')
			.click(function(){
				var $str = $(this).attr('title');
				var $by = $(this).attr('rel');
				var $dir = $('.order li[title="' + $('.order_title').html() + '"]').attr('rel');	
				$('.by_title').html( $str  );
				window.location = '?by='+ $by + '&dir='+$dir;	
			});
		$('.order li')
			.click(function(){
				var $str = $(this).attr('title');
				var $dir = $(this).attr('rel');
				var $by = $('.orderby li[title="' + $('.by_title').html() + '"]').attr('rel');
				$('.order_title').html( $str  );
				window.location = '?by='+ $by + '&dir='+$dir;										
			});									
	});
</script>
66 views