我一直在努力爭取在我的網站上運行這段代碼。 我希望用戶能夠通過單擊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 –