Hi,
Is it possible to add the date to this replacement tag, just like it is shown with the {NEW} tag.
Liro
How to add date to {RELATED:list_count:keyword}
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;
just after that paste this:
then find
Paste just after the last line before the comment this line:
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
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
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);
}
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
Code: Select all
$keyword_links .= " ".$date;
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
1.3 out, testing, testing...
Sponsoring 4 phpwcms Blog and Usermanagement
Sponsoring 4 phpwcms Blog and Usermanagement
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!
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!