hippievstony.com
I'm working with a wordpress website where I (mostly thanks to other very helpful people on this site) have gotten things to work very well. I am trying to get one last piece of the puzzle together and that is being able to allow people to post comments. My old version of the site could do this no problem but the new version is using a different method to access the database and the default comment templates aren't loading. I am trying to use some of my old code and insert it into my new template to hopefully get the comment posting ability back online (I need the field to appear where you type in your comment.)
This is my new 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_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');
$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">';
}
$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>';
echo '<p>' . $post['comment_content'] . '</p>';
echo '<p><small>-' . $post['comment_author'] . '</small></p>';
}
$lastPost = $post['post_id'];
}
if ($post['comment_approved']=1) {
if ($post['comment_author']){
echo '<p>' . $post['comment_content'] . '</p>';
echo '<p><small>-' . $post['comment_author'] . '</small></p>';
}
else echo '<p>no comment author</p>';
}
else echo '<p>comment awaiting approval</p>';
echo '</div>';
}
}
?>
and here is my old index.php:
<?php
get_header ();
?>
<div id="box">
<?php
$last = wp_get_recent_posts( '1');
$last_id = $last['0']['ID'];
echo $last_id;
?>
<div id="one">
<img src="http://www.hippievstony.com/wp-content/uploads/2009/11/tonyname.jpg"
<?php $my_query = new WP_Query ( 'author_name=tony' );
while ( $my_query->have_posts () ) :
$my_query->the_post () ?>
<div class="post">
<h3>
<a href="<?php the_permalink ();?>"><?php the_title ();?></a>
</h3>
<div class="entry">
<?php the_content ();?>
</div><!-- end entry div -->
<?php $withcomments = 1; ?>
<?php comments_template(); ?>
</div><!-- end post div -->
<?php
endwhile;/*end tony while have posts*/
?>
</div><!-- End one Div -->
<div id="two">
<img src="http://www.hippievstony.com/wp-content/uploads/2009/11/hippiename.jpg"
<?php
$my_query = new WP_Query ( 'author_name=hippie' );
while ( $my_query->have_posts () ) :
$my_query->the_post () ?>
<div class="post">
<h3>
<a href="<?php the_permalink ();?>"><?php the_title ();?></a>
</h3>
<div class="entry">
<?php the_content ();?>
</div><!-- end entry div -->
<?php $withcomments = 1; ?>
<?php comments_template(); ?>
</div><!-- end post div -->
<?php
endwhile;/*end hippie while have posts*/
?>
</div><!-- End two Div -->
continues on for the remaining author divs
and here I was fooling around trying to put the old working code into the new index.php:
foreach($posts as $post) {
echo '<div class="post">';
echo '<h3><a href="<?php the_permalink ();?>"><?php the_title ();?></a></h3>';
echo '<div class="entry">';
the_content ();
echo '</div>';
$withcomments = 1;
comments_template();
echo '</div>';
}
I'm probably not even close and I probably posted too much code, I'm hoping someone has some ideas about how to get whatever was happening in the older code to happen in the newer format.