The following replacement tag lets you insert the count of comments from within an article and displays it within an article listing. Great for using phpwcms as webblog or news overview if you have a comments section using the contet type "guestbook/comments" within the full articles. Note: You can only have one guestbook/comments section on every article.
Step 1
Put the file info.cassiel.comments.php into the folder "/phpwcms_template/inc_script/frontend_render/"
Step 2
Add the following code to "/config/phpwcms/conf.template_default.inc.php":
Code: Select all
// Comments replacement tag
$template_default['comments']['comment_one'] = '%d Comment'; // Text for one comment, %d gets replaced by num of comments
$template_default['comments']['comment_more'] = '%d Comments'; // Text for comments >1, %d gets replaced by num of comments
$template_default['comments']['comment_false'] = 'Write comment'; // Text for the link if no
$template_default['comments']['anchor_comments'] = 'comments'; // Anchor to jump to if comments
$template_default['comments']['anchor_form'] = 'comments_form'; // Anchor to jump to if no comments
$template_default['comments']['class_comments'] = 'comments'; // CSS class for the link if comments
$template_default['comments']['class_form'] = 'comments_form'; // CSS class for the link of no comments
Step 3
Edit your corresponding template file for your article listing and add the following code to the place where the count of the comments should be placed:
Code: Select all
[PHP]
// Strange hack, but it works
$my_article_id = "{ARTICLEID}";
$my_article_cid = $GLOBALS['content']['articles'][$my_article_id]['article_cid'];
echo('{COMMENTS:' . $my_article_id . ':' . $my_article_cid . '}')
[/PHP]
Step 4
Open the file "front.func.inc.php" within the folder "/include/inc_front/" and search for the function called "function url_search($query)". Now edit this function to match the following code:
Code: Select all
function url_search($query) {
// HACK BEGIN: Cassiel
// Match for anchor
$cnt = preg_match('/\#(.+)/i', $query, $anchor);
// Only if matching has worked
if ($cnt && $anchor) {
// Remove anchor from query
$query = preg_replace('/\#(.+)/i', '', $query);
// Get anchor's name
$anchor = $anchor[1];
}
// HACK:END
if ( substr($query,0,4) == '?id=') {
$noid = substr($query, 4);
$file = str_replace(',', '.', $noid).'.html';
//$file = str_replace(',', '.', $noid).'.phtml';
//$file = $noid.'.phtml';
} else {
$noid = substr($query,1);
$file = str_replace(',', '.', $noid).'.html';
//$file = str_replace(',', '.', $noid).'.phtml';
//$file = $noid.'.phtml';
}
// HACK:BEGIN Cassiel
$link = ($anchor) ? ' href="' . $file . '#' . $anchor . '"' : $link = ' href="' . $file . '"';
// HACK:END
return($link);
}
Step 6
Search within the same file for the function called "function js_url_search($query)" and edit it to match the following code:
Code: Select all
function js_url_search($query) {
// HACK BEGIN: Cassiel
// Match for anchor
$cnt = preg_match('/\#(.+)/i', $query, $anchor);
// Only if matching has worked
if ($cnt && $anchor) {
// Remove anchor from query
$query = preg_replace('/\#(.+)/i', '', $query);
// Get anchor's name
$anchor = $anchor[1];
}
// HACK:END
if ( substr($query,0,4) == '?id=') {
$noid = substr($query, 4);
$file = str_replace(',', '.', $noid).'.html';
//$file = str_replace(',', '.', $noid).'.phtml';
$file = $noid.'.phtml';
} else {
$noid = substr($query,1);
$file = str_replace(',', '.', $noid).'.html';
//$file = str_replace(',', '.', $noid).'.phtml';
$file = $noid.'.phtml';
}
// HACK:BEGIN Cassiel
$link = ($anchor) ? "onclick=\"location.href='" . $file . '#' . $anchor . "'" : "onclick=\"location.href='" . $file . "'";
// HACK:END
return($link);
}
Syntax of the replacement tag
{COMMENTS:1:2}
- The first value defines the article ID and the second value defines the category ID which contains the article. Both values are needed! Let both values be auto detected by the code posted on Step 3.
Notice
If you're not using the mod_rewrite function of phpwcms you don't have to add the core code hack in Steps 5 and 6.
Happy tagging,
Cassiel