我一直在努力争取在我的网站上运行这段代码。 我希望用户能够通过单击href链接以升序或降序对帖子进行排序。 当用户选择通过其他选项对帖子列表进行排序时,应该记住此选项,例如,标题,投票,日期。php&wordpress ASC/DESC使用href和排序
这里是我有远:
<?php $sort= $_GET['sort'];
if($sort == "A")
{
$order= "gdsr_sort=thumbs";
}
if($sort == "B")
{
$order= "orderby=title";
}
if($sort == "C")
{
$order= "orderby=date";
}
?>
<?php $updown= $_GET['updown'];
if($updown == "Y")
{$ascend= "ASC";} //this orders in ascending
if($updown == "Z")
{$ascend= "DESC";} //this orders in descending
?>
<a href="?sort=A&updown=<?php echo $updown?>">Thumbs</a>
<a href="?sort=B&updown=<?php echo $updown?>">Author</a>
<a href="?sort=C&updown=<?php echo $updown?>">Date</a>
<?php $sort= isset($_GET['sort']) ? $_GET['sort'] : "B";
?>
<a href="?updown=Y&sort=<?php echo $sort?>">Ascending</a>
<a href="?updown=Z&sort=<?php echo $sort?>">Descending</a>
<?php query_posts($order.'&order=$.ascend.'); ?>
<?php if (have_posts()) : ?>
<?php /* Start the Loop */ ?>
<?php while (have_posts()) : the_post(); ?>
排序的作品就好了,不过ASC/DESC没有做任何事情,整个事情只是停留DESC在href。
我不知道使用base-3号码会涉及什么?! http://www.something.com/?updown=1&sort=A 我使用$ _GET为你的意思是有URL中ASC和DESC的网址是什么? 感谢您的帮助 –
表示,其中0是没有排序字段的地方1,2,3,等国家,1是ASC和2 DESC,可以解析字符串你和确定哪些字段进行排序如何,第二种解决方案虽然更好。 –
我承认我在这里有点出乎我的意料, 你能帮我一个例子吗? Simon –