Hi All,
The script I'm using for news posting is designed so the comments for each news item are displayed with links like "/news/comments.php?action=list&newsid=1" but I'd like to have the comments displayed below each post, rather than on a separate page. There doesn't seem to be a variable to do this with the templates, so how can I accomplish it?
Thanks,
Trevor.
Hi Trevor,
The stock implementation of the news does not query for comments when it queries for news, so without some manual edits of the news.php file, this isn't possible.
That said, if you wanted to do some PHP editing, you could, but it would be a little involved and it would require some original thought. I don't officially support hacking up the files, but I can give you some pointers.
If you're interested, you would have to port some code from comments.php into news.php. Within the while(){} loop in news.php, you would have to query for comments like so:
PHP Code:
$getcomments=$DB->query("SELECT * FROM `unp_comments` WHERE newsid='$newsid'");
Following that, you could either manually design an output method yourself, or use the template engine to add templates custom designed to make it look good, using code based on this (but modified):
PHP Code:
eval('$comments_list_header = "'.unp_printTemplate('comments_list_header').'";');
unp_echoTemplate($comments_list_header);
if ($DB->num_rows($getcomments) > 0)
{
while ($comments = $DB->fetch_array($getcomments))
{
// grab and fix up comments
$c_id = $comments['id'];
$c_title = htmlspecialchars(stripslashes($comments['title']));
$c_name = htmlspecialchars(stripslashes($comments['name']));
$c_email = htmlspecialchars(stripslashes($comments['email']));
$c_date = unp_date($dateformat, $comments['date']);
$c_time = unp_date($timeformat, $comments['date']);
$c_text = nl2br(htmlspecialchars(stripslashes($comments['comments'])));
$c_ipaddress = $comments['ipaddress'];
$c_proxy = $comments['proxy'];
$c_text = $n->unp_doSmilies($c_text);
if ($isloggedin == 1)
{
eval('$removecommentlink = "'.unp_printTemplate('comments_list_commentbit_removecomment').'";');
}
else
{
$removecommentlink = '';
}
if ($isloggedin == 1)
{
eval('$ipaddressinfo = "'.unp_printTemplate('comments_list_commentbit_ipaddress').'";');
}
else
{
$ipaddressinfo = '';
}
eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
unp_echoTemplate($comments_list_commentbit);
}
}
else
{
echo 'None';
}