因此,我設法使用一些基本設置對帖子進行排序。我希望從日期,asc,date-dec,評論等這一週,每月,所有時間改變這一點。我也希望能包含以下代碼,將排序的頂部投票帖只,而不是所有帖子按周/月/所有時間對帖子進行排序
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: 好了,這裏是我有什麼,它不再起作用,所以我只是繼續和補充周/月/ alltime的地方,我認爲它應該去(我知道它不是正確的,但我不知道如何限制只有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>
你的問題是什麼? – janw
對不起,我編輯了OP一點。只想按星期,月份,所有時間排序我最受好評的帖子,而不是當前的日期(日期,日期,升序,標題,評論等) –
我以爲是,你卡在哪裏?所有代碼似乎都已到位。你只需要改變''選項值'''''和'case'語句。你已經想出了'orderby = meta_value_num'這是人們傾向於卡住的一點。 – janw