phdev Posted April 4, 2008 Share Posted April 4, 2008 Hey guys, I have pasted two php pages below. The first page does what I want - it lets the reverse-order-comments plugin work, whereas the second page doesn't seem to let it work, as the comments are in default order whether the plugin is enabled or not. First page also adjusts the date of every comment so they're always a certain number of days away from today's date. This keeps my comments looking fresh when they could be old.. I cannot for the life of me figure out how to make the second page use the date script and reverse order comments. Please help if you can. It's probably something obvious that i can't find cause I'm such a PHP noob. First page (old one that works) <?php // Do not delete these lines 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 ?> <p class="nocomments">This post is password protected. Enter the password to view comments.<p> <?php return; } } /* This variable is for alternating comment background */ $oddcomment = 'alt'; ?> <!-- You can start editing here. --> <?php if ($comments) : ?> <div class="thick_box" align="left"> <?php if ('open' == $post->comment_status) : ?> <div style="border-bottom: 1px dotted #d1e9ff; padding-bottom: 6px; margin-bottom: 6px; color: #333333;"> <h3>Submit Your <?php the_title(); ?> Review</h3></div> <?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 : ?> <span class="input_label">Name</span><br /> <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" class="textbox" /> <?php if ($req) echo "(required)"; ?> <br /> <span class="input_label">Mail</span><br /> <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" class="textbox" /> (will not be published) <?php if ($req) echo "(required)"; ?> <br /> <span class="input_label">Website</span><br /> <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" class="textbox" /> <br /> <?php echo dgrs_get_rating_fields(); ?> <?php endif; ?> <!--<p><small><strong>XHTML:</strong> You can use these tags: <?php echo allowed_tags(); ?></small></p>--> <br /> <span class="input_label">Your Review</span><br /> <textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4" class="textarea"></textarea> <br /> <input name="submit" type="submit" id="submit" tabindex="5" value="Submit Review!" class="button" /> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /> <?php do_action('comment_form', $post->ID); ?> </form> <?php endif; // If registration required and not logged in ?> <?php endif; // if you delete this the sky will fall on your head ?> </div> </div> <div id="content_right" align="left"> <form style="border-bottom: 1px solid #dfdfdf; padding-bottom: 10px; width: 232px; margin-bottom: 10px;" action="http://www.feedburner.com/fb/a/emailverify" method="post" target="popupwindow" onsubmit="window.open('http://www.feedburner.com', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"> <img src="/images/rss_title.jpg" alt="Subscribe" width="232" height="33" /><br /> <input name="email" type="text" id="email" class="rss_email" value="[email protected]" onclick="toggleTypeAndHitEnter2(this, 'onclick')" onblur="toggleTypeAndHitEnter2(this, 'onblur')" /> <div style="width: 232px; height: 30px;"> <div style="float: left;"> <input type="hidden" value="http://feeds.feedburner.com/~e?ffid=881925" name="url"/> <input type="hidden" value="Diet Pill Ratings" name="title"/> <input type="hidden" name="loc" value="en_US"/> <input type="image" name="submit" id="submit" src="/images/rss_button.jpg" /></div> <div style="float: right;"> <a href="http://feeds.feedburner.com/diet-pill-ratings"><img src="http://www.dietpillrating.com/images/reviews.gif" height="26" width="88" style="border:0" alt="" /></a></div> </div> </form> <h3 style="color: #333333;">Latest <?php the_title(); ?> Reviews</h3> <br /> <?php function dateOrdinalSuffixToUnixTimestamp($date) { $dateArray = explode(" ", $date); // Month Processing $MonthsArray = array( 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12, ); foreach($MonthsArray as $Month => $value) { if(strcmp(strtolower($Month), strtolower($dateArray[0])) == 0) { $DateChange['Month'] = (int)$value; } } // Day Processing $DateChange['Day'] = $dateArray[1]; $DateChange['Day'] = str_replace("st", "", $DateChange['Day']); $DateChange['Day'] = str_replace("nd", "", $DateChange['Day']); $DateChange['Day'] = str_replace("rd", "", $DateChange['Day']); $DateChange['Day'] = str_replace("th", "", $DateChange['Day']); $DateChange['Day'] = (int)$DateChange['Day']; // Year Processing $DateChange['Year'] = (int)$dateArray[2]; $returnTimestamp = mktime(0,0,0,$DateChange['Month'], $DateChange['Day'], $DateChange['Year']); return $returnTimestamp; } function dateToTimestamp($date) { $datefromdb = $date; $datefromdb = str_replace(" ", "", $datefromdb); $datefromdb = str_replace("-", "", $datefromdb); $datefromdb = str_replace(":", "", $datefromdb); $year = substr($datefromdb,0,4); $mon = substr($datefromdb,4,2); $day = substr($datefromdb,6,2); $hour = substr($datefromdb,8,2); $min = substr($datefromdb,10,2); $sec = substr($datefromdb,12,2); $orgdate = mktime($hour,$min,$sec,$mon,$day,$year); return $orgdate; } function format_date($format, $date) { $datefromdb = $date; $datefromdb = str_replace(" ", "", $datefromdb); $datefromdb = str_replace("-", "", $datefromdb); $datefromdb = str_replace(":", "", $datefromdb); $year = substr($datefromdb,0,4); $mon = substr($datefromdb,4,2); $day = substr($datefromdb,6,2); $hour = substr($datefromdb,8,2); $min = substr($datefromdb,10,2); $sec = substr($datefromdb,12,2); $orgdate = date($format,mktime($hour,$min,$sec,$mon,$day,$year)); return $orgdate; } $twoWeeksAgo = date("Y-m-d H:i:s", mktime(date("H"),date("i"), date("s"), date("m"), date("d") - 7, date("Y"))); $twoWeeksAgoTimestamp = dateToTimestamp($twoWeeksAgo); $firstDate = ""; $dateFormat = "Y-m-d H:i:s"; $adjustedDateFormat = "M jS, Y"; ?> <?php foreach ($comments as $comment) : ?> <?php if(strlen($firstDate) < 1) { $firstDate = get_comment_date('M jS, Y'); $firstDate = date($dateFormat, dateOrdinalSuffixToUnixTimestamp($firstDate)); $firstDateTimestamp = dateToTimestamp($firstDate); $dateAdjustment = $twoWeeksAgoTimestamp - $firstDateTimestamp; if($dateAdjustment < 1) { $dateAdjustment = 0; } $commentDate = date($adjustedDateFormat, mktime(0,0,$dateAdjustment, get_comment_date('m'), get_comment_date('d'), get_comment_date('Y'))); } else { $currentDate = get_comment_date('M jS, Y'); $currentDate = date($dateFormat, dateOrdinalSuffixToUnixTimestamp($currentDate)); $currentDateTimestamp = dateToTimestamp($currentDate); $commentDate = date($adjustedDateFormat, mktime(0,0, $dateAdjustment, get_comment_date('m'), get_comment_date('d'), get_comment_date('Y'))); } $showAdjustment = true; // $showAdjustment = false; # set to False to activate the real Comment Date ?> <div style="background-color: #fffce6; padding: 6px 4px 6px 4px; color: #aa9c4d;">Submitted by <?php comment_author_link() ?> <?php if($showAdjustment) { echo $commentDate; } else { comment_date('M jS, Y'); } ?></div> <div style="padding-left: 4px; font-size: 13px; color: #555555; font-family: Trebuchet MS, Arial, Helvetica, sans-serif; margin-top: 10px; margin-bottom: 18px;"> <?php if ($comment->comment_approved == '0') : ?> Your comment is awaiting moderation. <?php endif; ?> <?php $rating = dgrs_get_comment_ratings($comment->comment_ID); ?> <?php $rate_pieces = explode(": ", $rating); #print $rate_pieces[1]; ?> <? if ($rate_pieces[1] == 0) { ?><img src="/images/stars_0.jpg" style="margin-bottom: 8px;" /><? } ?> <? if ($rate_pieces[1] == 1) { ?><img src="/images/stars_1.jpg" style="margin-bottom: 8px;" /><? } ?> <? if ($rate_pieces[1] == 2) { ?><img src="/images/stars_2.jpg" style="margin-bottom: 8px;" /><? } ?> <? if ($rate_pieces[1] == 3) { ?><img src="/images/stars_3.jpg" style="margin-bottom: 8px;" /><? } ?> <? if ($rate_pieces[1] == 4) { ?><img src="/images/stars_4.jpg" style="margin-bottom: 8px;" /><? } ?> <? if ($rate_pieces[1] == 5) { ?><img src="/images/stars_5.jpg" style="margin-bottom: 8px;" /><? } ?> <?php comment_text() ?> </div> <?php /* Changes every other comment to a different class */ if ('alt' == $oddcomment) $oddcomment = ''; else $oddcomment = 'alt'; ?> <?php endforeach; /* end for each comment */ ?> <?php else : // this is displayed if there are no comments so far ?> <?php if ('open' == $post->comment_status) : ?> <!-- If comments are open, but there are no comments. --> <div class="thick_box" align="left"> <div style="border-bottom: 1px dotted #d1e9ff; padding-bottom: 6px; margin-bottom: 6px; color: #333333;"> <h3>Rate This Diet Pill</h3></div> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> <span class="input_label">Name</span><br /> <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" class="textbox" /> <?php if ($req) echo "(required)"; ?> <br /> <span class="input_label">Mail</span><br /> <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" class="textbox" /> (will not be published) <?php if ($req) echo "(required)"; ?> <br /> <span class="input_label">Website</span><br /> <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" class="textbox" /> <br /> <?php echo dgrs_get_rating_fields(); ?> <br /> <span class="input_label">Your Review</span><br /> <textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4" class="textarea"></textarea> <br /> <input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" class="button" /> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /> <?php do_action('comment_form', $post->ID); ?> </form> </div> <?php else : // comments are closed ?> <!-- If comments are closed. --> <p class="nocomments">Comments are closed.</p> <?php endif; ?> <?php endif; ?> </div> </div> </div> Second page (needs to be tweaked to perform the date adjustment and let reverse order comments plugin work) <?php // Do not delete these lines 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 ?> <p class="nocomments">This post is password protected. Enter the password to view comments.</p> <?php return; } } /* This variable is for alternating comment background */ $oddcomment = 'class="alt" '; ?> <!-- You can start editing here. --> <?php if ('open' == $post->comment_status) : ?> <h3 id="respond">Submit your <span class="highlight"><?php the_title(); ?></span> review</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 echo urlencode(get_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 : ?> <table class="dataentry"> <tr> <th><label for="author">Name</label></th> <td><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" /></td> </tr> <tr> <th><label for="email">E-Mail</label></th> <td><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" /></td> </tr> <tr> <th><label for="url">Website</label></th> <td><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" /></td> </tr> </table> <?php endif; ?> <?php if(function_exists("dgrs_get_rating_fields")) echo dgrs_get_rating_fields(); ?> <table class="dataentry"> <tr> <th><label for="comment">Review</label></th> <td><textarea name="comment" id="comment" cols="40" rows="10" tabindex="4"></textarea></td> </tr> <tr> <th></th> <td><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Review" /></td> </tr> </table> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /> <?php do_action('comment_form', $post->ID); ?> </form> <?php endif; // If registration required and not logged in ?> <?php endif; // if you delete this the sky will fall on your head ?> </div> <div id="reviewlist" class="yui-u"> <?php if ($comments) : ?> <h4>Latest Reviews</h4> <ol class="commentlist"> <?php foreach ($comments as $comment) : ?> <li id="comment-<?php comment_ID() ?>" class="comment"> <div class="meta"> <?php comment_date('F jS, Y') ?> <span class="author">(<?php comment_author_link() ?>)</span> </div> <div class="commenttext"> <div class="stars"> <?php $rating = dgrs_get_comment_ratings($comment->comment_ID); $rate_pieces = explode(": ", $rating); $stars = $rate_pieces[1]; for($i = 1; $i <= $stars; $i++) { ?><img src="<?php bloginfo('template_directory'); ?>/images/icon-star-large.gif" /><?php } for($i = 1; $i <= (5 - $stars); $i++) { ?><img src="<?php bloginfo('template_directory'); ?>/images/icon-star-large-gray.gif" /><?php } ?></div> <?php comment_text() ?> <?php if ($comment->comment_approved == '0') : ?> <p><em>Your comment is awaiting moderation.</em></p> <?php endif; ?> </div> </li> <?php endforeach; /* end for each comment */ ?> </ol> <?php else : // this is displayed if there are no comments so far ?> <?php if ('open' == $post->comment_status) : ?> <!-- If comments are open, but there are no comments. --> <?php else : // comments are closed ?> <!-- If comments are closed. --> <p class="nocomments">Comments are closed.</p> <?php endif; ?> <?php endif; ?> </div> </div> Link to comment https://forums.phpfreaks.com/topic/99489-wordpress-25-reverse-order-comments-and-relative-date-hack-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.