This Mod will allow each category to have it's own Sort Order.
I created this so that some of my categories can be displayed in sequence using the image name but others I just want to display with the latest first ie. using date_order.
Two things to note:
1) It stops the default Sort order set using the Admin Panel - Settings Page.
2) The Mod in this forum for allowing users to select their own sort order will not work on the Categories page. However it will still work in the Search and New Images pages (same page really)
The Mod it quite easy to install but make sure you backup/make copy of your files first. Just in case
Step 1.
Add 2 new fields to your categories table
sort_order varchar(5) Default "ASC"
sort_field varchar(20) Default "image_name"
Thanks to V@no (Helps us unfortunate newbies all the time
)
Heres the link for the DB installer..
Category Sort Install Just download the zip file, unzip it to your root directory and call it from your browser.
Step 2.
Backup ./global.php
Edit ./global.php
4images v1.7Search for ...
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images
FROM ".CATEGORIES_TABLE." c
LEFT JOIN ".IMAGES_TABLE." i ON (i.cat_id = c.cat_id AND i.image_date >= $new_cutoff AND i.image_active = 1)
GROUP BY c.cat_id
ORDER BY c.cat_order, c.cat_name ASC";
Replace with ...
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, c.sort_order, c.sort_field, COUNT(i.image_id) AS new_images
FROM ".CATEGORIES_TABLE." c
LEFT JOIN ".IMAGES_TABLE." i ON (i.cat_id = c.cat_id AND i.image_date >= $new_cutoff AND i.image_active = 1)
GROUP BY c.cat_id
ORDER BY c.cat_order, c.cat_name ASC";
4images v1.7.1Search for ...
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with ...
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field
Step 3.
Backup ./categories.php
Edit ./categories.php
Search for
sql line containing ...
ORDER BY
Replace Whole Line with... ORDER BY ".$cat_cache[$cat_id]['sort_field']." ".$cat_cache[$cat_id]['sort_order']."
Step 4.
Backup ./lang/yourlang/admin.php
Edit ./lang/yourlang/admin.php
Insert just ABOVE
?>
at end of page
//--------------Images Sort-------------------------
//---Used by Category Sort Option Mod ---
//--------------------------------------------------
$lang['image_order'] = "Sort images by";
$image_order_optionlist = array(
"image_name" => "Name",
"image_date" => "Date",
"image_downloads" => "Downloads",
"image_votes" => "Votes",
"image_rating" => "Rating",
"image_hits" => "Hits"
);
$lang['image_sort'] = "Ascending/Descending";
$image_sort_optionlist = array(
"ASC" => "Ascending",
"DESC" => "Descending"
);
//--------------------------------------------------
//---End of Category Sort Option Mod ---
//--------------------------------------------------
Step 5.
Backup ./admin/categories.php
Edit ./admin/categories.php
Search for ...
if ($action == "savecat") {
$error = array();
$cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
$cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
$cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
Immediatley After
INSERT these 2 lines...
$sort_order = trim($HTTP_POST_VARS['imagesradio']);
$sort_field = trim($HTTP_POST_VARS['imagesorder']);
Search for ...
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";
Replace with ...
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, '$sort_order', '$sort_field')";
Search for ...
show_textarea_row($lang['field_description_ext'], "cat_description", "", $textarea_size);
Immediatley After,
INSERT this...
$imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
foreach ($image_order_optionlist as $key => $val) {
$imgsort_dropdown .= "<option value=\"$key\"";
if ($config['image_order'] == $key) {
$imgsort_dropdown .= " selected=\"selected\"";
}
$imgsort_dropdown .= ">".$val."</option>\n";
}
$imgsort_dropdown .= "</select>\n";
foreach ($image_sort_optionlist as $key => $val) {
$imgsort_radio .= "<INPUT type=\"radio\" name=\"imagesradio\" value=\"$key\"";
if ($config['image_sort'] == $key) {
$imgsort_radio .= " checked";
}
$imgsort_radio .= ">".$val."\n";
}
show_custom_row($lang['image_order'], $imgsort_dropdown);
show_custom_row($lang['image_sort'], $imgsort_radio);
Search for ...
if ($action == "savecat") {
$error = array();
$cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
$cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
$cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
Immediatley After,
INSERT this...
$sort_order = trim($HTTP_POST_VARS['imagesradio']);
$sort_field = trim($HTTP_POST_VARS['imagesorder']);
Search for ...
if ($action == "updatecat") {
$error = array();
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);
$cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
$cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
$cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
$cat_hits = intval(trim($HTTP_POST_VARS['cat_hits']));
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
Immediatley After,
INSERT this...
$sort_order = trim($HTTP_POST_VARS['imagesradio']);
$sort_field = trim($HTTP_POST_VARS['imagesorder']);
Search for ...
$sql = "UPDATE ".CATEGORIES_TABLE."
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
WHERE cat_id = $cat_id";
Replace with ...
$sql = "UPDATE ".CATEGORIES_TABLE."
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, sort_order = '$sort_order', sort_field = '$sort_field'
WHERE cat_id = $cat_id";
Search for ...
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_order, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
FROM ".CATEGORIES_TABLE."
WHERE cat_id = $cat_id";
Replace with ...
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_order, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field
FROM ".CATEGORIES_TABLE."
WHERE cat_id = $cat_id";
Search for ...
show_textarea_row($lang['field_description_ext'], "cat_description", $cat_row['cat_description'], $textarea_size);
Immediatley After
INSERT this ...
$imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
foreach ($image_order_optionlist as $key => $val) {
$imgsort_dropdown .= "<option value=\"$key\"";
if ($cat_row['sort_field'] == $key) {
$imgsort_dropdown .= " selected=\"selected\"";
}
$imgsort_dropdown .= ">".$val."</option>\n";
}
$imgsort_dropdown .= "</select>\n";
foreach ($image_sort_optionlist as $key => $val) {
$imgsort_radio .= "<INPUT type=\"radio\" name=\"imagesradio\" value=\"$key\"";
if ($cat_row['sort_order'] == $key) {
$imgsort_radio .= " checked";
}
$imgsort_radio .= ">".$val."\n";
}
show_custom_row($lang['image_order'], $imgsort_dropdown);
show_custom_row($lang['image_sort'], $imgsort_radio);
Search for ...
if ($action == "modifycats") {
if ($msg != "") {
printf("<b>%s</b>\n<p>", $msg);
}
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
FROM ".CATEGORIES_TABLE."
ORDER BY cat_order, cat_name ASC";
$result = $site_db->query($sql);
Replace with ....
if ($action == "modifycats") {
if ($msg != "") {
printf("<b>%s</b>\n<p>", $msg);
}
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, sort_order, sort_field
FROM ".CATEGORIES_TABLE."
ORDER BY cat_order, cat_name ASC";
$result = $site_db->query($sql);
THAT'S IT PEOPLE.
Now just go into your Admin Panel - Edit Categories and set your sort orders. If you created the 2 extra table fields above the default sort order for all existing categories will be image_name ASC.
Good luck
Fugaziman