Post by jcd » Tue May 03, 2011 10:00 pm

Hi,

I am using the Q CMS module on opencart version 149 and to create a blog, using the "articles".

I want the user to be able to add articles and for the most recent articles to appear at the top of the page.

I don't want to use sort order to do it because I think it will become difficult to manage after a few hundred posts have been made.

I thought there would be an easy way of doing this so please correct me if I am going about it like an idiot.

At the moment, if I enable sorting by date, editing catalog/model/cms/article.php and adding:
$sort ='(date.added)'
immediately before
$sql .= " ORDER BY "

Then the first article always appears at the top.

I have tried editing article.php
And replacing the line with:

$sort = '"(array_reverse(a.date_added)"'
In the hope that this would reverse the order of the items, but it didn't work.

I don't know enough about PHP and I want to get this project finished.

Any help is much appreciated,

-J

"If it can't be fixed with a sledgehammer then it can't be fixed"


jcd
Newbie

Posts

Joined
Tue May 03, 2011 9:43 pm

Post by jcd » Thu May 12, 2011 8:14 am

Solved, in catalog\model\cms\article.php. Found:

if ($order == 'DESC') {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
and replaced it with:
if ($order == 'DESC') {
$sql .= " DESC";
} else {
$sql .= " DESC";
}

Cheers!

-J

"If it can't be fixed with a sledgehammer then it can't be fixed"


jcd
Newbie

Posts

Joined
Tue May 03, 2011 9:43 pm

Post by susanjoy » Tue May 17, 2011 3:01 pm

Thank you, this helped me out tremendously in combination with changing the code right above that from:

Code: Select all

	if (in_array($sort, $sort_data)) {
$sql .= " ORDER BY " . $sort;
			} else {
				$sql .= " ORDER BY ad.name";	
			}
to

Code: Select all

	if (in_array($sort, $sort_data)) {
				$sort = 'a.date_added';
$sql .= " ORDER BY " . $sort;
			} else {
				$sql .= " ORDER BY ad.name";	
			}
...so that it sorts by date instead of alphabetically.

Newbie

Posts

Joined
Mon Nov 29, 2010 11:44 am
Who is online

Users browsing this forum: No registered users and 6 guests