**我在 search.php 页面上使用此代码根据链接点击从最旧到最新和最旧到最新的帖子
注意:但是现在我的默认搜索表单在此页面上不起作用**
<?php
$args = array(
'order' => (isset($_GET['orderby']) ? $_GET['orderby'] : 'ASC')
);
query_posts($args);
?>
<div class="sort_by">
<span>Sort by:</span>
<span class="relevance <?php if(!isset($_GET['order'])){ echo 'activesearch';} ?>"><a href="?s=<?php echo $_GET['s']; ?>">Relevance</a></span>
<span class="newest <?php if(isset($_GET['order']) && $_GET['order']=='DESC'){ echo 'activesearch';}else{ echo '';} ?>"><a href="?s=<?php echo $_GET['s']; ?>&orderby=post_date&order=DESC" >Newest</a></span>
<span class="oldest <?php if(isset($_GET['order']) && $_GET['order']== 'ASC'){ echo 'activesearch';}else{ echo '';} ?>"><a href="?s=<?php echo $_GET['s']; ?>&&orderby=post_date&order=ASC">Oldest</a></span>
</div>
最佳答案
当您使用query_posts()
时,您应该保存原始查询。像这样的东西应该对你有帮助。
global $wp_query;
query_posts(
array_merge(
array('orderby' => 'DESC', 'order'=> 'date'),
$wp_query->query
)
);
或
global $query_string;
parse_str($query_string, $args);
$args['orderby'] = 'date';
$args['order'] = 'DESC';
query_posts( $args );
关于php - 单击 Wordpress 更改顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536315/