sorting the {RELATED} tag

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
Ben
Posts: 558
Joined: Wed 14. Jan 2004, 08:05
Location: Atlanta
Contact:

sorting the {RELATED} tag

Post by Ben »

I'm trying to include a list of related articles based on a particular keyword. The tag I'm using is {RELATED:100:California}. The problem, is that the related links seem to be sorting based upon the last edit time of each article. Is there a way to sort the results of a related tag alphabetically? It seems that a minor change to the code at line 391 of content.func.inc.php should be able to change what results are sorted on.

Code: Select all

// related articles based on keywords, inspired by Magnar Stav Johanssen
if( ! ( strpos($content["all"],'{RELATED:')===false ) ) {
	if (!$no_content_for_this_page && $content["articles"][$aktion[1]]["article_keyword"]) {
		$related_keywords = $content["articles"][$aktion[1]]["article_keyword"];
	}
	$content["all"] = preg_replace('/\{RELATED:(\d+)\}/e','get_related_articles($related_keywords,$aktion[1],$template_default["related"],"$1",$db);',$content["all"]);
	$content["all"] = preg_replace('/\{RELATED:(\d+):(.*?)\}/e','get_related_articles("$2",$aktion[1],$template_default["related"],"$1",$db);',$content["all"]);
}
Thanks for any help!
Ben
Posts: 558
Joined: Wed 14. Jan 2004, 08:05
Location: Atlanta
Contact:

Post by Ben »

Ok, I've answered my own question. In case this helps anyone, here's how to sort ascending by article title for the results of the {RELATED} tag:

in front.func.inc.php line 1645, change this line:

Code: Select all

"ORDER BY article_tstamp DESC".$limit.";";
to this:

Code: Select all

"ORDER BY article_title ASC".$limit.";";
sdicivit
Posts: 4
Joined: Thu 21. Oct 2004, 13:52

other sortings

Post by sdicivit »

Very interesting, but, what if I'd like to have the articles sorted by start date?
Thanx
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

Im not at home....

But have you tried:
"ORDER BY article_date ASC".$limit.";";
I have no idea if it works....
http://www.studmed.dk Portal for doctors and medical students in Denmark
sdicivit
Posts: 4
Joined: Thu 21. Oct 2004, 13:52

Post by sdicivit »

Thank you for the answer, but in the meanwhile I have found it. If that can be usefull for someone, to sort them by start date you can do it like this:
"ORDER BY article_begin ASC".$limit
Bye bye.
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

sdicivit wrote:Thank you for the answer, but in the meanwhile I have found it. If that can be usefull for someone, to sort them by start date you can do it like this:
"ORDER BY article_begin ASC".$limit
Bye bye.
thank you fore sharing it with us..... :wink:
http://www.studmed.dk Portal for doctors and medical students in Denmark
Post Reply