View Full Version : category sorting / set categories order
Hi Simon!
I have created a new category "Computers" in ROOT. It was at the end of course. Than I moved up to third position using the admin. I also checked in the db, it has now "order" 3.
But there is no change. Computers is still displayed on last position.
Anway I would like to change, that all categories are always sorted by titel alphabetically. I will not have a specific order. Please show how to change that.
Thank you,
gb
Simon Gooffin
12-14-2005, 11:53 AM
I'm sure your categories order does not work because of MySQL 4.1 version. If you want to have them sorted alphabetically you should change your queries.
*** open Dir.php and find the following function ***
function getCategoriesByParent($aCategory = 0, $aFull = FALSE, $aSubcategories = 0)
*** change ****
$sql .= "ORDER BY t1.`order`) ";
*** to ***
$sql .= "ORDER BY t1.`title`) ";
*** save changes ***
It should work
Simon Gooffin
12-14-2005, 12:03 PM
additional for mysql 4.1
$sql .= "ORDER BY t1.`title`) ";
$sql .= "ORDER BY `title`";
check your directory. I've just done changes
thanks. i see.
what would be the sql changes to get those " Sort by Pagerank | Clicks | Alphabetical" working?
greetings,
gb
Simon Gooffin
12-14-2005, 06:15 PM
well, it depends....
if you use cookies for your sorting you should take cookie value in your sql query, check it and use for sql query. that's the main point.
for say your query can be modified in the following way:
$order = $_COOKIE['order'] ? $_COOKIE['order'] : $gDirConfig['link_sorting'];
$sql = "ORDER BY {$order}";
Hi Simon!
I'm using code that you have posted once here before the forum crash:
in tpl:
Sort by Pagerank ({$smarty.server.REQUEST_URI|add_url_param:'order' :pagerank}) | Clicks ({$smarty.server.REQUEST_URI|add_url_param:'order' :clicks}) | Alphabetical ({$smarty.server.REQUEST_URI|add_url_param:'order' :title})
in dir.php
require_once('includes/config.inc.php');
if ($_GET['order'])
{
setcookie( "links_sorting", $_COOKIE['links_sorting'], time() - 3600, '/' );
setcookie( "links_sorting", $_GET['order'], 0, '/' );
}
$gDirConfig['links_sorting'] = $_COOKIE['links_sorting'] ? $_COOKIE['links_sorting'] : $gDirConfig['links_sorting'];
require_once('DirDb.php');
The changes above don't work.
Greetings,
gb
Simon Gooffin
12-15-2005, 07:27 AM
Well, please check your directory now. I tried to check myself and It seems it's ok.
Use the following code:
if ($_GET['order'])
{
setcookie( "links_sorting", $_COOKIE['links_sorting'], time() - 3600, '/' );
setcookie( "links_sorting", $_GET['order'], 0, '/' );
}
$cookie = $_COOKIE['links_sorting'] ? $_COOKIE['links_sorting'] : $gDirConfig['links_sorting'];
$gDirConfig['links_sorting'] = $_GET['order'] ? $_GET['order'] : $cookie;
and sql query should be modified a bit. Please compare these Dir.php and Dir.php.bak file. getLinksByCategory function
nice. thanks a lot simon.
greetings,
gb
Simon Gooffin
12-15-2005, 09:33 AM
you are welcome ;)
what i don not understand are the two lines in dir.php 342/343
$sql .= "ORDER BY `{$order}` {$order_type}) ";
$sql .= "ORDER BY `{$order}` {$order_type} ";
why twice? i know it doesn't work if i comment one of them, but i would like to know why for future changes without the need to bug you.
additional question:
How can i define if the custom sorting should be ASC or DESC? User shouldn't have the choice, i want to define it.
greetings,
gb
Simon Gooffin
12-15-2005, 09:40 AM
the first line is used for MySQL 4.0 query.. you see it has ).. it's an end of UNION all query.. in v4.1 you should have common ORDER BY.
for say you have 2 UNION SELECT queries. you should have a common order for them.
you have an option in your admin panel that allows you to choose ASC or DESC order in yoru select queries. you see you have order_type.. you may directly use ASC or DESC instead of that variable
thanks for clarifying.
it seems that sorting by clicks needs DESC and sorting by title ASC. How will i do that?
greetings,
gb
Simon Gooffin
12-15-2005, 10:14 AM
just add something like this before code you asked about above:
$order_type = ($order == 'title') ? 'ASC' : 'DESC';
Simon Gooffin
12-15-2005, 11:23 AM
you are welcome ;)
Sai_dallas
03-08-2006, 08:00 PM
Sorry to bother you guys.
:wallbash: Where is Dir.php file
Sorry to bother you guys.
:wallbash: Where is Dir.php file
Hi Sai_dallas
Look in your classes folder.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.