How to add date to {RELATED:list_count:keyword}

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
liro
Posts: 41
Joined: Thu 16. Jun 2005, 08:29
Location: Netherlands
Contact:

How to add date to {RELATED:list_count:keyword}

Post by liro »

Hi,

Is it possible to add the date to this replacement tag, just like it is shown with the {NEW} tag.

Liro
Pappnase

Post by Pappnase »

liro
Posts: 41
Joined: Thu 16. Jun 2005, 08:29
Location: Netherlands
Contact:

Post by liro »

Yes, add the date of the article?
With {new} you get:
date article - article title
with {related} you get:
article title.

I want the date of the article too.

Liro
liro
Posts: 41
Joined: Thu 16. Jun 2005, 08:29
Location: Netherlands
Contact:

Post by liro »

Anyone, is this possible?
Perhaps some kind of hack?

Liro
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi Liro,

frist, the warnings:
1°: I'm not a php coder, so if more clever solutions exist, trust them.
2°: I hacked front.func, maybe there is a better way to get where you want.
3°: I got what you need after some try and error ;)

I put this because I'm kinda keen on go and hacking the code and very often it's not necessary, there are better solutions, anyway, here you go:

Tested here, with {RELATED:5:test}
http://www.memoire-meyer.be/index.php?id=3,9,0,0,1,0

Open front.func.inc.php
find related function;

Code: Select all

function get_related_articles($keywords, $current_article_id, $template_default, $max_cnt_links=0, $dbcon) {
	// find keyword for current article used for RELATED replacementtag
	// prepared and inspired by Magnar Stav Johanssen
just after that paste this:

Code: Select all

  $format = $format ? $format : "long";
  $article_id = $article_id ? $article_id :
  $GLOBALS["content"]["article_id"];
  $date = '';
  $sql  = 'select article_created from '.DB_PREPEND.'phpwcms_article where article_id = ' .$article_id;

  if($result = mysql_query($sql)) {
    $row  = mysql_fetch_row($result);
    $date = international_date_format(
        $GLOBALS["template_default"]["date"]["language"],
        $GLOBALS["template_default"]["date"][strtolower($format)],
        $row[0]
    );
    mysql_free_result($result);
  }
then find

Code: Select all

		// related things
		$target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
		if($result = mysql_query($sql, $dbcon)) {
			$count_results = mysql_num_rows($result); $count = 0;
			while ($row = mysql_fetch_row($result)) {
				$count++;
				if($template_default["link_length"] && strlen($row[1]) > $template_default["link_length"]) {
					$article_title = substr($row[1], 0, $template_default["link_length"]).$template_default["cut_title_add"];
				} else {					$article_title = $row[1];
				}
				$keyword_links .= $template_default["link_before"].$template_default["link_symbol"];
				$keyword_links .= '<a href="index.php?id='.$row[2].','.$row[0].',0,0,1,0"';
				$keyword_links .= $target.">".html_specialchars($article_title)."</a>";
				
				//try to remove possible unwanted after - if not enclosed before.link.after
Paste just after the last line before the comment this line:

Code: Select all

				$keyword_links .= "&nbsp; ".$date;
Voilà it works!
If u want to set another kind of date just change
$format = $format ? $format : "long";
with the format you want (see conf.template_default.inc.php)

Hope it does it.
Cheers
antonis
Posts: 35
Joined: Mon 7. Jun 2004, 14:55

Post by antonis »

Hi!

I tried the solution proposed here on a 1.1 RC4 installation and it partially works.

The problem is that all articles show the same date instead of each showing it's own date. I think that the date displayed for all articles is the date that the first article was created when the scipt was initially installed.

I tried reading (sql query) the date from other fields like article_tstamp, article_begin, etc but I get the same problem... it seems like there is a problem with "reading" and distinguishing the correct article_id for each different article... or something like that.

any suggestions...? Thanks in advace!
Post Reply