So, this is complicated: There's two parts of our site, one part is in WordPress (posts/pages), the other is reviews, cast pages, and search results (which I wrote the code myself for).
They share a centralized navigation system, where I want to include recent comments. I could use a Plugin, but that won't work for the pages outside of WordPress.
So, as I did with the "Recent Posts" section, I'm trying to write my own code.
I've got it working, without issue, but want to replace the "comment_content", with the permalink to the post. Since the permalink's not kept in the comment data (but linked via the ID, I'm assuming), I don't know how to do it.
Here's the code I've got now, that lists the last 10, but excludes my two main authors:
<?php
// set your infomation.
$dbhost='xxxxxxxxxx';
$dbusername='xxxxxxxx';
$dbuserpass='xxxxxxxxxxx';
$dbname = 'xxxxxxxxxxxxx';
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//select the database
mysql_select_db($dbname) or die('Cannot select database');
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
$keywords = explode(" ", $search);
$query = "SELECT * FROM wordpress_comments WHERE comment_approved='1' AND user_id != '3' AND user_id != '2' ORDER BY comment_ID DESC LIMIT 10" ;
$result = mysql_query($query) or die(mysql_error());
?>
<?php
while($row = mysql_fetch_array($result))
{
echo "<img src=\"../images/sub_bullet.gif\" alt=\"\"><a href=\"";
echo("".$row["comment_author_url"]."");
echo "\">";
echo("".$row["comment_author"]."");
echo "</a> ";
echo("".$row["comment_content"]."");
echo "<br>";
}
?>
I know it's not the most elegant code in the world, but it (sort of) works for what I want to do. Can someone point me in the right direction on how to get the permalink from the info available in the comments data?