• Resolved rbaibich

    (@rbaibich)


    Hi!

    I got K2 so I could take it apart and learn something while I’m making my website, but I’m having some trouble with having comments on the homepage itself.

    If you wanna know exactly what I wanna do, take a look at this.

    This is my single.php right now:


    <?php get_header(); ?>

    <div class="content">

    <div class="primary">

    <?php include (TEMPLATEPATH . '/theloop.php'); ?>
    <?php comments_template(); ?>

    </div>

    <?php /*get_sidebar();*/ ?>

    </div>

    <?php get_footer(); ?>

    So I thought I’d just put “<?php comments_template(); ?>” into the loop and everything would be fine. Apparently not…

    How can I make it call the comments for each post from the main blog index and not only in single pages?

Viewing 8 replies - 1 through 8 (of 8 total)
  • To include the comments template on the home page, you can temporarily reset the wp_query class and fool WordPress about what page you’re on:

    <?php
    $wp_query->is_single = true;
    comments_template();
    $wp_query->is_single = false;
    ?>

    Thread Starter rbaibich

    (@rbaibich)

    Tried it, but that only works for the last post. All the others come up with an error.

    Any other ways of making it work?

    Thread Starter rbaibich

    (@rbaibich)

    Shameless bump… Still looking for an answer.

    Did you place it within The Loop? It needs to be reiterated for each post. If you did, then try this:

    <?php
    global $wp_query;
    $wp_query->is_single = true;
    comments_template();
    $wp_query->is_single = false;
    ?>

    If that also fails to work, how about:

    <?php
    global $wp_query;
    $wp_query->is_home = false;
    $wp_query->is_single = true;
    comments_template();
    $wp_query->is_home = true;
    $wp_query->is_single = false;
    ?>

    Basically I’ve never seen resetting $wp_query->is_single fail to work on the home page, barring some unusual querying going on in the background.

    Thread Starter rbaibich

    (@rbaibich)

    Yeah, I placed it in the loop. It seems that K2’s comments PHP is the problem: when the second post comes I get this error:

    Fatal error: Cannot redeclare k2_comment_type_detection() (previously declared in /home/.../betatest/wp-content/themes/beto/comments.php:15) in /home/.../betatest/wp-content/themes/beto/comments.php on line 23

    Edit:

    This is the piece of code that’s not working, btw:

    function k2_comment_type_detection($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
    global $comment;
    if (preg_match('|trackback|', $comment->comment_type))
    return $trackbacktxt;
    elseif (preg_match('|pingback|', $comment->comment_type))
    return $pingbacktxt;
    else
    return $commenttxt;
    }

    That’s in comments.php? It should really go into the theme’s functions.php. That way you’re not constantly redeclaring it in cases like this. You can also wrap the function (while it’s in comments.php) in this if statement:

    if(!function_exists('k2_comment_type_detection')) {
        function k2_comment_type_detection() {

        …

         }
    }

    Hmm. Fixing k2 stuff now…

    Thread Starter rbaibich

    (@rbaibich)

    Yeah… What can you do…

    I already remove that from k2 svn (can’t remember which revision) not long ago.

    k2 don’t need that function anymore since we already replace it with WP get_comment_type().

    Permanently remove the whole function and replace comments.php k2_comment_type_detection() with get_comment_type()

    There should be 2 places not including the function.

    Cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Comments on the homepage (w/ a JS slidedown)’ is closed to new replies.