WordPress.org

Ready to get started?Download WordPress

Forums

need most commented, but with c2c_get_custom (3 posts)

  1. yongfook
    Member
    Posted 8 years ago #

    I use c2c's get_custom function to retrieve little thumbnails for each post, which I put in a "thumb" custom field.

    I'd really like to be able to show a list of Most Commented (or Recently Commented) but with the ability to use the values from custom fields - but most plugins just give you a link.

    I presume this is going to require a little hacking of the most commented script - but it's not like I can just slot an extra bit into the script like this, is it? Guess I should just try, but I'm afraid of breaking stuff:

    function mdv_most_commented($no_posts = 5, $before = '<li>', $after = '</li>', $show_pass_post = false) {
    global $wpdb;
    $request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
    $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
    if(!$show_pass_post) $request .= " AND post_password =''";
    $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
    $posts = $wpdb->get_results($request);
    $output = '';
    if ($posts) {
    foreach ($posts as $post) {
    $post_title = stripslashes($post->post_title);
    $comment_count = $post->comment_count;
    $permalink = get_permalink($post->ID);

    //new line here!!

    $MYCUSTOMVALUE = c2c_get_custom('thumb');

    $output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $MYCUSTOMVALUE . '</a> (' . $comment_count.')' . $after;
    }
    } else {
    $output .= $before . "None found" . $after;
    }
    echo $output;
    }

    that wouldn't work, right..?

    or would it?

    Or would I have to at least do a require_once and call the c2c script beforehand??

    please help!

  2. yongfook
    Member
    Posted 8 years ago #

    anyone?

    anyone??

    I tried this:

    if ($posts) {
    foreach ($posts as $post) {
    $post_title = stripslashes($post->post_title);
    $comment_count = $post->comment_count;
    //new line here!!!111
    $thumb = c2c_get_recent_custom("thumb");

    $permalink = get_permalink($post->ID);
    $output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a>'.$thumb.' (' . $comment_count.')' . $after;
    }

    And it works fine - BUT, that just gets the most recent custom field regardless of post. I really need to use c2c_get_custom() but I get an error - I think it's because the above isn't strictly a wordpress loop. Also tried $post->c2c_get_custom() and that won't work either.

    Any ideas?? Very close now, I think!

  3. yongfook
    Member
    Posted 8 years ago #

    ok I thought this would DEFINITELY work, but it doesn't :(

    I basically put a mini loop inside the most-commented script, so I could use the c2c_get_custom function. It doesn't do anything though...can anyone tell me why?

    if ($posts) {
    foreach ($posts as $post) {
    $post_title = stripslashes($post->post_title);
    $comment_count = $post->comment_count;
    //
    //
    //new stuff here
    //
    //
    $id = $post->ID;
    query_posts('p=$id');
    while (have_posts()) : the_post();
    $thumb = c2c_get_custom('thumb');
    endwhile;
    //
    //
    //end of new stuff
    //
    //
    $permalink = get_permalink($post->ID);
    $output .= $before.$id.$thumb . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a>'.$thumb.' (' . $comment_count.')' . $after;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic