My solution is to create a replacement tag that mimics the appearance of an article list but that filters the articles based on a date flag in the title of the article.
As snipped from the comments in the below code block:
"The function uses the TITLE of the article to filter the list. The first part
of the article name must be the date (Ymd) followed by the actual title. Date
and title must be delimited with a blank space " ".
Only articles with a title date higher than the one specified in the parameter
will be displayed. By setting the $date to "NOW" the **** will be done
using todays date as set on the server."
By implementing a replacement tag like this it is my intention to use the normal article functionality to provide what the users perceive as an event calendar. The only caveat I can see in this is to ensure that the users make sure to set the title of the article correctly, as there is nothing to enforce this by default in PHPWCMS.
To implement this feature, copy the below code to a file that you name something like rt_ARTICLE_LIST_BY_DATE.php and place it in the template/inc_script/frontend_renderer folder.
Invoke the functionality by placing the following replacement tag in your template or content part:
{ARTICLE_LIST_BY_DATE:id to page:date to filter by ('NOW' for todays date):class of the container div:the number of articles to display:a message to show when the list is empty}
Code: Select all
<?php
/* ======================================================================
A date based article summary display tag. Only shows articles with a title that
is more "recent" than the given date.
Replacement tag by Johan Strömquist, Further AB, 2008-07-08
========================================================================= */
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------
if(strpos($content["all"],'{ARTICLE_LIST_BY_DATE') !== false) { // TAG in use ?
$content["all"] = preg_replace('/\{ARTICLE_LIST_BY_DATE:(.*?):(.*?):(.*?):(.*?)\}/ie', 'article_list_by_date("$1","$2","$3","$4")', $content["all"]);
}
// ----------------------------------------------------------------
function article_list_by_date($cat_id, $date, $class="", $limit="", $empty="") {
/* ======================================================================
Parameters:
$cat_id The id of the page from which articles are fetched
$date Only articles "newer" than this date are showed
$class The class for the container div
$limit An integer to limit the number of displayed articles
$empty A string to display in case the list is empty
The function uses the TITLE of the article to filter the list. The first part
of the article name must be the date (Ymd) followed by the actual title. Date
and title must be delimited with a blank space " ".
Only articles with a title date higher than the one specified in the parameter
will be displayed. By setting the $date to "NOW" the **** will be done
using todays date as set on the server.
========================================================================= */
global $content;
$empty = htmlentities($empty);
if ($date == "NOW") $date = date("Ymd", time());
$x_class_01 = '<div class="' . $class . '">';
$x_class_02 = '</div>';
$articleInfo = get_actcat_articles_data($cat_id);
foreach ($articleInfo as $id => $article) {
$title = explode(" ", $article["article_title"]);
if (is_numeric($art_date = array_shift($title)) && $art_date > $date) {
$title = implode(" ", $title);
$replace .= "<div class = 'calDate'>" . $art_date . "</div>" .
"<a href = '?aid=" . $id . "'>" .
$title .
"</a><br />";
if ($article["article_summary"]) $replace .= $article["article_summary"];
}
$counter ++;
if ($counter > $limit - 1) break;
}
if (!$replace) $replace = $empty;
$replace = $header . $x_class_01 . $replace . $x_class_02;
return $replace;
}
?>
(Thanks to DF6IH for providing me with a working regexp! )