所以我设法用一些基本设置对我的帖子进行了排序。我想从 date-asc、date-dec、comments 等周、月、所有时间更改它。我还希望合并以下代码,仅对投票最多的帖子进行排序,而不是对所有帖子进行排序
meta_key=votes_count&orderby=meta_value_num&order=DESC&posts_per_page=10
目前我的工作评分最高的页面,它对我的日期升序、标题等进行排序:
<?php
if( isset($_GET['o']) && $_GET['o'] != '')
{
$order = $_GET['o'];
switch($order)
{
case 'date-asc': $orderby = 'order=ASC';
$msg = 'Date Ascending';
break;
case 'date-desc': $orderby = 'order=DESC';
$msg = 'Date Descending(default)';
break;
case 'date-mod': $orderby = 'orderby=modified';
$msg = 'Date Modified';
break;
case 'title-asc': $orderby = 'orderby=title&order=ASC';
$msg = 'Title A-Z';
break;
case 'title-desc': $orderby = 'orderby=title&order=DESC';
$msg = 'Title Z-A';
break;
case 'comment': $orderby = 'orderby=comment_count';
$msg = 'Comment Count';
break;
}
}
else
{
$orderby = 'order=DESC';
$msg = 'Date Descending (default)';
}
?>
<div id="content">
<div id="sorter-container">
<h2 id="sort-heading">Posts ordered by:<?php echo $msg; ?></h2>
<select id="order-by">
<option value="date-desc" <?php echo (!isset($order) || $order == '' || $order == 'date-desc')? 'selected="selected"':''; ?>>Date Desc. (default)</option>
<option value="date-asc" <?php echo ($order == 'date-asc')? 'selected="selected"':''; ?>>Date Asc</option>
<option value="date-mod" <?php echo ($order == 'date-mod')? 'selected="selected"':''; ?>>Date Modified</option>
<option value="title-desc" <?php echo ($order == 'title-desc')? 'selected="selected"':''; ?>>Title Desc.</option>
<option value="title-asc" <?php echo ($order == 'title-asc')? 'selected="selected"':''; ?>>Title Asc.</option>
<option value="comment" <?php echo ($order == 'comment')? 'selected="selected"':''; ?>>Comments Count</option>
</select>
</div>
<script type="text/javascript">
var orderby = jQuery('#order-by');
var str;
orderby.change(function(){
str = jQuery(this).val();
window.location.href = "<?php echo home_url(); ?>/top-rated/?o="+str;
});
</script>
EDIT2: 好的,这就是我所拥有的,它不再起作用了,所以我只是继续并将周/月/所有时间添加到我认为应该去的地方(我知道它不正确,但我不确定如何限制排序仅 7 天等。
<?php
if( isset($_GET['o']) && $_GET['o'] != '')
{
$order = $_GET['o'];
switch($order)
{
case 'week': $orderby = 'meta_key=votes_count&orderby=meta_value_num&order=DESC&WEEK&posts_per_page=10';
$msg = 'This Week (default)';
break;
case 'month': $orderby = 'meta_key=votes_count&orderby=meta_value_num&order=DESC&MONTH&posts_per_page=10';
$msg = 'This Month';
break;
case 'alltime': $orderby = 'meta_key=votes_count&orderby=meta_value_num&order=DESC&ALLTIME&posts_per_page=10';
$msg = 'All Time';
break;
else
{
$orderby = 'order=DESC';
$msg = 'This Week (default)';
}
?>
<div id="content">
<div id="sorter-container">
<h2 id="sort-heading">Posts ordered by:<?php echo $msg; ?></h2>
<select id="order-by">
<option value="week" <?php echo (!isset($order) || $order == '' || $order == 'week')? 'selected="selected"':''; ?>>This Week (default)</option>
<option value="month" <?php echo ($order == 'month')? 'selected="selected"':''; ?>>This Month</option>
<option value="alltime" <?php echo ($order == 'alltime')? 'selected="selected"':''; ?>>All Time</option>
</select>
</div>