commenting closed on an unusual wordpress site, desperate
Posted: Mon Dec 28, 2009 3:49 pm
In order to make this wordpress site do what I want, it seems I have gutted a lot of the common functions they use to make things happen and now I'm kind of alone with it. I have a multi-author site where each author gets one column div to post things he/she is working on and to encourage people to stay crafty and creative I sort the divs from left to right by most recent poster so they are the ones you first see when you load the page. To make this work, I used mysql queries to join some tables and then output the data.
I'm having trouble with making sure the comments display properly for each post as well as making the comment field (where you would type in your name and comment) appear below each post. Here is my index.php:
and here is the comments.php file in case you think it might help:
I have removed the two lines that are supposed to output the comment field:
$withcomments='1';
comments_template();
because they output all comments for all posts below each post. I have put those two lines in a lot of different places, but it's not working. I can post my comments.php file if you think it might help.
I got through a lot of this with help from others but now have come to a real dead end. Being able to post comments is a big part of the site so I would greatly appreciate any help. Thanks
tony
I'm having trouble with making sure the comments display properly for each post as well as making the comment field (where you would type in your name and comment) appear below each post. Here is my index.php:
Code: Select all
<?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 the comments.php file in case you think it might help:
Code: Select all
<?php
if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<h2><?php _e('Password Protected'); ?></h2>
<p><?php _e('Enter the password to view comments.'); ?></p>
<?php return;
}
}
$oddcomment = 'alt';
?>
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
<div class="commentmetadata">
<strong><?php comment_author_link() ?></strong>, <?php _e('on'); ?> <a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> <?php _e('at');?> <?php comment_time() ?></a> <?php _e('Said:'); ?> <?php edit_comment_link('Edit Comment','',''); ?>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.'); ?></em>
<?php endif; ?>
</div>
<?php comment_text() ?>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; ?>
</ol>
<?php else : ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<?php endif; ?>
<?php endif; ?>
<?php if (comments_open()) : ?>
<h3 id="respond">Leave a Reply</h3>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( $user_ID ) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout »</a></p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="40" tabindex="1" />
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" />
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" />
<label for="url"><small>Website</small></label></p>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> <?php _e('You can use these tags:'); ?> <?php echo allowed_tags(); ?></small></p>-->
<p><textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; ?>
<?php endif; ?>$withcomments='1';
comments_template();
because they output all comments for all posts below each post. I have put those two lines in a lot of different places, but it's not working. I can post my comments.php file if you think it might help.
I got through a lot of this with help from others but now have come to a real dead end. Being able to post comments is a big part of the site so I would greatly appreciate any help. Thanks
tony