yet another simple replacement tag to display the number of times an article has been read. This is an enhancement of {MOST_READ}, which is required to be installed. See other thread for instructions on that one.
To use, simply add the following to frontend_render:
// AUTHOR: Jens Zetterström {ART_READ}
// DESCRIPTION: Returns the number of times an article has been read.
// REQUIREMENTS: {MOST_READ} enhancement: phpwcms_article_read_count table, etc
// USAGE: {ART_READ:article_id:category_id}
// I put it in my article template file so that
// it appears for each article:
// {ART_READ:<?php echo $GLOBALS["content"]["article_id"];?>:<?php echo $GLOBALS["content"]["cat_id"];?>}
function get_article_read_cnt($art_id, $cat_id, $dbcon)
{
$count = 0;
$sql ="SELECT count( article_id ) as art_cnt
FROM ".DB_PREPEND."phpwcms_article_read_count
WHERE article_id = $art_id
AND cat_id = $cat_id ";
if($result = mysql_query($sql, $dbcon))
{
$row = mysql_fetch_assoc($result);
$count = $row["art_cnt"];
mysql_free_result($result);
}
return $count;
}
// {ART_READ}
if( ! ( strpos($content["all"],'{ART_READ:')===false ) )
{
$content["all"] = preg_replace('/\{ART_READ:(\d+):(\d+)\}/e','get_article_read_cnt($1,$2,$db);',$content["all"]);
}
Did you add the table phpwcms_article_read_count to your mysql database?
I noticed that I added an ID column with autoincrement to the table as I was getting an error of duplicate records. See if that solves it. That also requires that you specify which columns you are inserting in content.article.inc.php:
which version of phpwcms do you use ?
tag work fine, but when i put there you PHP code ty make this tag more dynamic, this script return empty values. and so i doesn't work.
You'll need to supply it with an article_id and category_id:
{ART_READ:article_id:cat_id}
You can use php variables if you put it in the article itself:
{ART_READ:<?php echo $GLOBALS["content"]["article_id"];?>:<?php echo $GLOBALS["content"]["cat_id"];?>}
I have it like that in my article template file, so that it appears for each article. If that doesn't work try using [PHP]echo ...[/PHP]. I haven't tried that yet.
I don't know why I implemented it with both id's, article_id should be enough. That was kinda stupid, but that's the way it is for now. Maybe I'll change it later...
Sorry for the trouble. I don't know what could be the problem. Try putting an echo statement in the function to see that it actually enters the function and go from there, for example: