我使用以下循环按类别显示帖子(&A);我想根据下拉选择器重新订购
if (!isset($qry))
$qry = new WP_Query(array(\'category_name\'=>$GLOBALS[\'city\'],\'order\'=>$orderby));
if ($qry->have_posts($orderby)) {
$do_the_post = null;
if (is_single($orderby)) {
$do_the_post = true;
} else {
$qry->the_post($orderby);
$do_the_post = false;
}
$user = get_userdata($post->post_author);
到目前为止,使用我找到的一些代码
here我有:
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="sorter-container">
<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>
//JQUERY
<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(); ?>/gallery/?o="+str;
});
</script>
正在调用$orderby,因为该命令不起作用-我的PHP最好是初级的,但有人能告诉我这里出了什么问题吗?
谢谢
最合适的回答,由SO网友:Jesse 整理而成
我想问题是
$qry = new WP_Query(array(\'category_name\'=>$GLOBALS[\'city\'],\'order\'=>$orderby));
就这么说吧
$orderby 是
orderby=title&order=ASC那么WP\\u Query的order参数将如下所示:
\'order\'=>\'orderby=title&order=ASC\'
但是,order参数仅接受:
ASC and DESC.
你应该这样做:
WP_Query(\'category_name=\'.$GLOBALS[\'city\'].\'&\'.$orderby);