======================================
REORDER ARTICLES 1.0 - sNews 1.5.31
======================================
Origins:This mod is an updated version of
Article Sorting 0.1b for sNews 1.5.26 by J. Rivera (a.k.a Celebro). It has been updated for use with sNews 1.5.31 using
Onlip's Drop-down Menu Mod which was based on Philmoz's
Article list under Categories Mod.
Purpose:Onlip's Drop-down Menu Mod can be used to display the categories function in a horizontal navigation bar, and have the article-links in each category display as drop-down menus. This "Reorder Articles" mod will allow you to set the order in which articles will be displayed in each category drop-down as well as on each category page (including the home page).
Usage:When publishing a new article (extra or page), or editing an existing article (extra or page), a new "Article Order" field will be visible below the Editor buttons under the textarea block. By default, this field will have a "0" in it, when you edit an existing article or create a new one. Articles with a "0" setting will be sorted by the publishing date (default sNews method). You can assign any order number to an article... from 1 to 99,999 and the articles will be listed with the lower number at the top and the higher one at the bottom.
To have articles displayed in order within each category, using pre-determined blocks of numbers for each category... such as 200 per block... will give you lots of room in each category. An an example, all articles in category_1 would use numbers from 101 to 300. Articles assigned to category_2 would use numbers 301 to 500, and so on. Chances are you wouldn't have more than 200 articles in any given category but... if you think you would... then you could have a greater spread between the start and end of each block of numbers.
If you do happen to use the same order number for two or more articles, then those articles would be displayed in the order of their published date.
BEFORE MODDING - make a back-up of your existing snews.php file. And, if you are a PHP Newbie... pay close attention as you work. It's a good idea to make a copy of strings before you mod them, paste them above the un-modded string, comment the un-modded string out, then mod the copy. This way, you always have the default string handy. It doesn't hurt to add the same comment line above every mod point as a locator you can always search for later... such as
# Article Reordering Mod.
MODIFICATIONS: All modifications are done in the snews.php file.
1. Add a new field to your articles database table.In phpMyAdmin, click on the articles table in your database to display its fields. Add a new field at the End of the Table. The field name is
artorder, the field type is
int(11), with a length of
11.
2. In the Language variables array: search for
$l['cat_listSEF']. At the end of the string, add the blue part so it looks like this:
settings,files,logout,artorder';
3. Dropdown Categories Menu Function - If you haven't added it before, add this function under
function login_link(). If you have it added already, replace it with this function:
// DISPLAY CATEGORIES DROPDOWN MENU, with Reorder Article mod
function categories_dropdown() {
$linkingSwitch=0; // set to 1 to make category name act as a link to the category page.
$showHomeAsCAT=0; // set to 0 to omit the Home link.
$categorySEF = get_id('category');
/* *** 'HOME' IS A PAGE NOT A CATEGORY! *** */
if($showHomeAsCAT==1){ echo '<li>'."\r\n".'<a href="'.db('website').'" title="'.s('website_title').'">'.l('home').'</a>'."\r\n".'</li>'."\r\n"; }
/* ^^^^^ BUT HERE IT IS ANYWAY ^^^^^ */
$query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$calc_num_query = "SELECT * FROM ".db('prefix')."articles WHERE published = '1' AND category = $r[id] AND published = '1' ORDER BY artorder ASC";
$cm_result = mysql_query($calc_num_query);
$num_rows = mysql_num_rows($cm_result);
if ($num_rows > 0) { // shortened version of next line, bakercad
// if (($num_rows == 0 && isset($_SESSION[db('website').'Logged_In'])) || $num_rows > 0) {
$category_title = $r['seftitle'];
$echo= '<li>'."\r\n".'<a href="'.db('website').$r['seftitle'].'/" title="'.$r['description'].'" ';
if ($linkingSwitch == 1){$echo.=' href="'.db('website').$r['seftitle'].'/" title="'.$r['description'].'"';}
//next line replaces 2 lines to remove # of articles in brackets after category names in horiz. nav menu
$echo.='>'.$r['name'].'</a>'."\r\n";
//$echo.='>'.$r['name'];
//$echo.= (s('num_categories') == 'on' ? ' ('.$num_rows.')' : '').'</a>'."\r\n";
$echo.='<ul>'."\r\n";
while ($art = mysql_fetch_array($cm_result)) {
$echo.= '<li><a href="'.db('website').$category_title.'/'.$art['seftitle'].'/" title="'.$art['title'].'">'.$art['title'].'</a></li>'."\r\n"; }
echo $echo."</ul></li>\r\n"; }
}
echo "\r\n \r\n <!-- end category listing -->";
}
4. In function pages() - search for:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";
5. In function extra() - search for:
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY id DESC";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY artorder ASC";
6. In function center() - search for:
$query_articles .= " AND position <> 3 ORDER BY date DESC";
and replace it with:
$query_articles .= " AND position <> 3 ORDER BY artorder ASC";
7. In function sitemap() - search for:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY date";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY artorder ASC";
8. In function menu_articles($start, $size) - search for:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC LIMIT $start, $size";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY artorder ASC LIMIT $start, $size";
9. In function form_articles($contents) - search for:
$frm_publish = $r['published'] == 1 ? 'ok' : '';
and paste the following string underneath it:
$artorder = $r['artorder'];
And... about 20 lines or so further down... find:
$frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
and the same string below it:
$artorder = $r['artorder'];
10. Further down in In function form_articles($contents) - search for:
html_input('button', 'include', '', 'Include', '', 'button', 'onclick="tag(\'include\')"', '', '', '', '', '', '', '', '');
echo '</p>';
and under that, paste in this new section:
echo '<p>';
html_input('text', 'artorder', 'ao', $artorder, 'Article Order', 'style_me', '', '', '', '', '', '', '', '', '');
echo '</p>';
And... in the same function, further down, find:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id ASC";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";
11. In function admin_articles($contents) - search for:
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY date DESC";
and replace it with:
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY artorder ASC";
12. In function processing() - search for:
$date = date('Y-m-d H:i:s');
and paste this string underneath it:
$artorder = $_POST['artorder'];
Then... a little further down find:
$article_limit = $_POST['article_limit'];
and paste in the same string again:
$artorder = $_POST['artorder'];
And... further down some more, find:
mysql_query($query_begin."'$word_filter_enable' WHERE name = 'word_filter_enable' LIMIT 1;");
and paste the following below it:
mysql_query($query_begin."'$artorder' WHERE name = 'artorder' LIMIT 1;");
13. Still in function processing() - search for this large string:
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");
and replace it with this one:
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, artorder) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', '$artorder')");
And... a little further down, find this string:
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta' WHERE id = '$id' LIMIT 1;");
and replace it with this one:
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta', artorder = '$artorder' WHERE id = '$id' LIMIT 1;");
---------------------------------------------------------------
I hope someone finds this mod useful. I did.
