• hippievstony.com

    So when I add the two lines:

    $withcomments = ‘1’;
    comments_template();

    inside my php code in index.php, it outputs “comments are closed” for every post instead of displaying the comment fields where you type in your comments. Comments are enabled in my settings page. Here is my index.php:

    <?php
    get_header ();
    ?> 
    
    <div class="comments-template"> 
    
    <div id="box"> 
    
    <?php
    $qry =  "SELECT u.id, user_nicename, post_date, post_content, post_title, post_type, post_excerpt, comment_content, comment_count, comment_author, comment_approved, wp_posts.ID as post_id
             FROM wp_posts
             INNER JOIN wp_users AS u ON post_author = u.id
             LEFT JOIN wp_comments ON wp_posts.ID = comment_post_ID
             WHERE post_type='post'
             ORDER BY user_nicename ASC, post_date DESC"; 
    
    $res = mysql_query($qry); 
    
    if ($res) { 
    
        while ($row = mysql_fetch_assoc($res)) {
           $author[$row['user_nicename']][]=$row;
        } 
    
        foreach($author as $k => $v) {
            $orderbydate[$v[0]['post_date']][$k] = $v;
        }
        krsort($orderbydate);
        foreach ($orderbydate as $k => $v) {
            ksort($orderbydate[$k], SORT_STRING);
        }
    } 
    
    $divIds = array('one', 'two', 'three', 'four', 'five', 'six', 'seven');
    $i = 0; 
    
    foreach ($orderbydate as $date => $authors) {
        foreach ($authors as $author=> $posts) { 
    
              echo '<div id="'.$divIds[$i++].'">';
                   if($author=="tony") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/tonyname.jpg">';
                   }
                   elseif($author=="hippie") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/hippiename.jpg">';
                   }
                   elseif($author=="eriku") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/erikuname.jpg">';
                   }
                   elseif($author=="ben") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/benname.jpg">';
                   }
                   elseif($author=="hingyi") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/hingyiname.jpg">';
                   }
                   elseif($author=="chris") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/chrisname.jpg">';
                   }
                   elseif($author=="maya") {
                        echo '<img src="http://www.hippievstony.com/wp-content/uploads/mayaname.jpg">';
                   }
    
                $lastPost = null;
    
                     foreach($posts as $post) {                               
    
                         if ($lastPost != $post['post_id']) { 
    
                         echo '<h2>' . $post['post_title'] . '</h2><small>' . $post['post_date'] . '</small>';
                         echo '<p>' . $post['post_content'] . '</p>';
                         echo '<p>' . $post['post_excerpt'] . '</p>';
                              $comment_counter=1;
                              while($post['comment_count']>=$comment_counter) {
                                  if ($post['comment_approved']=1) {
                                       if ($post['comment_author']){
                                            echo '<p>' . $post['comment_content'] . '</p>';
                                            echo '<p><small>-' . $post['comment_author'] . '</small></p>';
                                            }
                                            }
                                  $comment_counter++;
                              }
                         $lastPost = $post['post_id'];
                         } 
    
                         $withcomments = '1';
                         comments_template();
                      }                                 
    
                         echo '</div>'; 
    
        } 
    
    } 
    
    ?> 
    
    </div><!-- end box div -->
    <?php 
    
    get_sidebar ();
    get_footer (); 
    
    ?>

    I’ve been trying to get the fields so people can comment for a long time, thanks for any ideas

    tony

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter shatterjack

    (@shatterjack)

    is there anything i need to be aware of since I am calling my posts and comments from the database with sql queries and don’t have a typical loop?

    Don’t know if it is always true, but my theme’s comments.php has a test ‘if (have_comments())’. ‘have_comments’ is set in query.php, so I’m guessing that if you don’t use WP_Query, it won’t get set, and no comments will be found.

    Thread Starter shatterjack

    (@shatterjack)

    the thing is that my comments are outputting ok for each post, but just not the field to type in new comments (they were added before I changed my whole theme code around).

    Thread Starter shatterjack

    (@shatterjack)

    I couldn’t find “have_comments” in my comments.php so I don’t think that’s it. I know it’s going through my comments.php file because I tweaked it and I got an error. It’s just, I don’t think I’m going about doing my page in the way that wordpress likes, and not the way anyone else has done so I’m having a real hard time finding help in past posts. Because I am customizing the order and arrangement of the posts, I have to output them in a similar way and I’ve gotten everything to output eventually except the field to type in your comment and register. It’s very elusive for me!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘“comments are closed” when they should be open!’ is closed to new replies.