Page 1 of 1

sorting the {RELATED} tag

Posted: Wed 22. Sep 2004, 09:58
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!

Posted: Wed 22. Sep 2004, 10:06
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.";";

other sortings

Posted: Tue 14. Dec 2004, 12:27
by sdicivit
Very interesting, but, what if I'd like to have the articles sorted by start date?
Thanx

Posted: Tue 14. Dec 2004, 12:51
by frold
Im not at home....

But have you tried:
"ORDER BY article_date ASC".$limit.";";
I have no idea if it works....

Posted: Wed 15. Dec 2004, 17:10
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.

Posted: Wed 15. Dec 2004, 17:12
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: