Please login or register.

Login with username, password and session length

Author Topic: MOD - Re-order Articles within Categories  (Read 4327 times)

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6290
  • Semantically Challenged
    • snews.ca
MOD - Re-order Articles within Categories
« on: May 14, 2007, 05:06:24 AM »

======================================
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:
Quote
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:
Quote
// 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:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id";
and replace it with:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";
5. In function extra() - search for:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY id DESC";
and replace it with:
Quote
$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:
Quote
$query_articles .= " AND position <> 3 ORDER BY date DESC";
and replace it with:
Quote
$query_articles .= " AND position <> 3 ORDER BY artorder ASC";
7. In function sitemap() - search for:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY date";
and replace it with:
Quote
$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:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC LIMIT $start, $size";
and replace it with:
Quote
$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:
Quote
$frm_publish = $r['published'] == 1 ? 'ok' : '';
and paste the following string underneath it:
Quote
$artorder = $r['artorder'];
And... about 20 lines or so further down... find:
Quote
$frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
and the same string below it:
Quote
$artorder = $r['artorder'];
10. Further down in In function form_articles($contents) - search for:
Quote
html_input('button', 'include', '', 'Include', '', 'button', 'onclick="tag(\'include\')"', '', '', '', '', '', '', '', '');
echo '</p>';

and under that, paste in this new section:
Quote
echo '<p>';
html_input('text', 'artorder', 'ao', $artorder, 'Article Order', 'style_me', '', '', '', '', '', '', '', '', '');
echo '</p>';

And... in the same function, further down, find:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id ASC";
and replace it with:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";
11. In function admin_articles($contents) - search for:
Quote
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY date DESC";
and replace it with:
Quote
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY artorder ASC";
12. In function processing() - search for:
Quote
$date = date('Y-m-d H:i:s');
and paste this string underneath it:
Quote
$artorder = $_POST['artorder'];
Then... a little further down find:
Quote
$article_limit = $_POST['article_limit'];
and paste in the same string again:
Quote
$artorder = $_POST['artorder'];
And... further down some more, find:
Quote
mysql_query($query_begin."'$word_filter_enable' WHERE name = 'word_filter_enable' LIMIT 1;");
and paste the following below it:
Quote
mysql_query($query_begin."'$artorder' WHERE name = 'artorder' LIMIT 1;");
13. Still in function processing() - search for this large string:
Quote
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:
Quote
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:
Quote
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:
Quote
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. :)
« Last Edit: October 26, 2007, 02:38:50 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mosh

  • Dev Invitee
  • Hero Member
  • *****
  • Karma: 78
  • Posts: 522
  • Awesome day :)
MOD - Re-order Articles within Categories
« Reply #1 on: May 14, 2007, 11:43:53 AM »

oooo wow, thank you key, you know, you rocks   :cool:
Logged

DigitalDingo

  • Newbie
  • *
  • Karma: 0
  • Posts: 14
    • Dingo's Incredibly Small Part of the Internet
MOD - Re-order Articles within Categories
« Reply #2 on: August 02, 2007, 12:56:08 PM »

Would it be possible for you to make an updated version of this MOD for sNews 1.6 or even for your sNews 1.6 Enhanced MOD?

Most of the steps are straightforward in 1.6 and works even in Enhanced but especially the two 'mysql_query' strings are causing me trouble since they don't exists in 1.6.
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6290
  • Semantically Challenged
    • snews.ca
MOD - Re-order Articles within Categories
« Reply #3 on: August 02, 2007, 08:19:53 PM »

Quote from: DigitalDingo
Would it be possible for you to make an updated version of this MOD for sNews 1.6 or even for your sNews 1.6 Enhanced MOD?
Most of the steps are straightforward in 1.6 and works even in Enhanced but especially the two 'mysql_query' strings are causing me trouble since they don't exists in 1.6.
I'd love to Dingo... but I just don't have the time to do it soon. Feel free to work on it yourself, though, and when you get it working OK... just post your changes for 1.6 here under this same topic so others will be able to find it too, and a new post under the 1.6 Mods & Addons with a link that leads to your solution here. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

DigitalDingo

  • Newbie
  • *
  • Karma: 0
  • Posts: 14
    • Dingo's Incredibly Small Part of the Internet
MOD - Re-order Articles within Categories
« Reply #4 on: August 05, 2007, 01:09:43 PM »

I have played around a bit, and now it works with sNews 1.6. Here are the steps needed to be changed in order to make it work:

10. The new section should be this ('echo' before 'html_input'):
Code: [Select]
echo '<p>';
echo html_input('text', 'artorder', 'ao', $artorder, 'Article Order', 'style_me', '', '', '', '', '', '', '', '', '');
echo '</p>';
12. This string doesn't exist anymore:
Code: [Select]
mysql_query($query_begin."'$word_filter_enable' WHERE name = 'word_filter_enable' LIMIT 1;");Instead search for this one:
Code: [Select]
$ufield = array('website_title' => $website_title,'home_sef' => $home_sef,'website_description' => $website_description,'website_keywords' => $website_keywords,'website_email' => $website_email,'contact_subject' => $contact_subject,'language' => $language,'charset' => $charset,'date_format' => $date_format,'article_limit' => $article_limit,'rss_limit' => $rss_limit,'display_page' => $display_page,'comments_order' => $comments_order,'comment_limit' => $comment_limit,'word_filter_file' => $word_filter_file,'word_filter_change' => $word_filter_change,'display_new_on_home' => $display_new_on_home,'display_pagination' => $display_pagination,'num_categories' => $num_categories,'approve_comments' => $approve_comments,'word_filter_enable' => $word_filter_enable,);and insert the following string directly below it:
Code: [Select]
mysql_query($query_begin."'$artorder' WHERE name = 'artorder' LIMIT 1;");All other steps are the same as in your original post.

But there's still a problem I can't solve: Articles sorted under '0' will be sorted with the newest at the bottom. Do you know how to change this?
« Last Edit: August 24, 2007, 08:44:26 PM by Keyrocks »
Logged