• Here is some code to display a link to the last (n) commented posts:
    <?php $query = “SELECT ID, post_title, comment_author, comment_date FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID ORDER BY $tablecomments.comment_date DESC LIMIT 5”;
    $result = mysql_query($query);
    while ($data = mysql_fetch_row($result)) {
    echo “$data[2]
    $data[1]
    \n”;
    } ?>
    If you changed your tables and database in anyway you would obviously need to edit the sql calls accordingly, but other than that this works just fine.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Anonymous

    Oh I forgot to tell you what to do with the above code, simply insert this wherever you want the data to show up, and BAM! There it is.
    I am using thi son my site now, https://www.chrisjdavis.org/ it listed under, get this; recently commented!
    Later

    Great feature. Can you explain what character “&#92” stands for or should that literally be put into the code? Put into my page this way just displays the title of my post with an /n after it and no hyperlinking.

    It’s a slash. \ I had to post it to my blog to figure it out. LOL

    Argh… a forward slash that is. ??
    I can’t seem to get it to work though. I am assuming the code isn’t being displayed properly here. I viewed the source and copied but still no luck.

    kenko

    (@kenko)

    replace the echo line with this
    echo "$data[2]
    $data[1]<br
    />
    ";

    mamabean

    (@mamabean)

    That worked, thanks!!

    Thread Starter Anonymous

    Is there a WordPress 1.01 version of this hack?

    *crosses fingers*
    function recent_comments($limit = 5) {
    global $wpdb, $tableposts, $tablecomments, $siteurl, $blogfilename;
    $out = '';
    $sql = "SELECT ID, post_title, comment_ID, comment_author, comment_date, comment_content FROM $tableposts, $tablecomments";
    $sql .= " WHERE $tableposts.ID=$tablecomments.comment_post_ID";
    $sql .= " ORDER BY $tablecomments.comment_date DESC LIMIT $limit";
    $posts = $wpdb->get_results($sql);
    foreach ($posts as $post) {
    $permalink = $siteurl.'/'.$blogfilename.'/?p='.$post->ID.'&c=1#comment-'.$post->comment_ID;
    $comment = substr(stripslashes($post->comment_content), 0, 50);
    $out .= '

    PLEASE post code to the wiki and LINK TO IT from here. Thank you.

    Thread Starter Anonymous

    I would use this function for the creation of a url:
    get_permalink($recentcomment->post_id)
    Can you put that in the script?

    This hack is now officially dead, go here: https://www.chrisjdavis.org/index?p=439 for the last release.
    Author_list is dead as well, as is the copyright hack, at least as far as releasing them to the general public.
    You will still be able to find the code @http://www/chrisjdavis.org but I won’t be releasing them here anymore. I might announce when something has reached a decent level of maturity, but that is about it.

    This is the right code
    <li id="last_comments">
    <?php _e('Last Comments:'); ?>
    <ul>
    <?php
    $query = "SELECT ID, comment_post_ID, comment_author, comment_content FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID ORDER BY $tablecomments.comment_date DESC LIMIT 5";
    $result = mysql_query($query);
    while ($data = mysql_fetch_row($result)) {
    if (!$data[2]) {
    $data[2]="Anonymous";
    }
    echo "<li>";
    echo "[$data[2]] <a href="index.php?p=$data[1]#comments">";
    echo substr($data[3],'0','80');
    echo "...</a></li>";
    } ?>
    </ul>
    </li>

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Last (n) comments…’ is closed to new replies.