How to order the articles in the Sections module

18.9.1. How to order the articles in the Sections module

Sometimes you may not be satisfied with the order of articles in the Sections module. To change it, edit the following line of the modules/Sections/index.php:

$result = sql_query("select artid, secid, title, content, counter 
from ".$prefix."_seccont where secid=$secid $querylang", $dbi);

Change it to[1]

$result = sql_query("select artid, secid, title, content, counter 
from ".$prefix."_seccont where secid=$secid $querylang ORDER BY artid DESC", $dbi);
Tip Changing the order of results
 

This is a typical example of changing the order of results of a database selection. This was achieved by solely adding "ORDER BY artid DESC" to the SQL query string. In plain text, this means "order the results by descending article id". The "right way" would of course be to sort by time. But lacking an extra timestamp field, we make use of the fact that later articles have a higher id. Thus, sorting by descending id will give last articles first. Think of this simple trick whenever you seek a simple way to change the order of some results.

Notes

[1]

See How to sort in Sections.

 

Site Info v2.2.2

Last SeenLast Seen
Server TrafficServer Traffic
  • Total: 339,028,574
  • Today: 56,536
Server InfoServer Info
  • Oct 19, 2017
  • 06:42 pm PDT
 
 

Daily Inspiration