通过在顶部使用$\\u GET函数
<?php $sort= $_GET[\'sort\'];
if($sort == "title")
{
$order= "orderby=title";
}
if($sort == "date")
{
$order= "orderby=date";
}
?>
您可以使用以下链接:
<a href="?sort=title" <?php if ($sort == "title"){ echo \'style="color:gray"\'; } ?>>title</a><a href="?sort=date" <?php if ($sort == "date"){ echo \'style="color:gray"\'; } ?>>Date</a>
或下拉列表:
<form action="" method="get">
<select name="sort" id="sorting">
<option value="title" <?php if ($sort == "title"){ echo \'selected="selected"\'; } ?> >Sort by title</option>
<option value="date" <?php if ($sort == "date"){ echo \'selected="selected"\'; }?> >Sort by publication date</option>
</select>
<input type="submit" value="Submit" /></form>
然后是循环
<?php $loop = new WP_Query(\'cat=5&showposts=-1&\'.$order.\'&order=DEC\'); ?><?php while ( $loop->have_posts() ) : $loop->the_post(); ?>.........<?php endwhile; ?>