Show comments on front page
-
Been perusing the support and wiki. I’d like to have comments for a post show up on the front page after the post – not just the comment count/link.
-
Okay I believe part of it involves using the <?php include(“wp-comments.php”) ?> to put the comments on the page – and I know that in the url if c=1 then it shows comments. How do I tell it to make c=1 when viewing the frontpage of the blog?
I don’t see how this is possible – though I could well be proved wrong.
Head over to https://wordlog.com/ (no permalinks there)
If you hover the title of the most recent post, you see this:
https://wordlog.com/index.php?p=74
and if you hover the comments link:
https://wordlog.com/index.php?p=74#comments
So any sort of redirect would only go to that post. Adding another post would mean changing a redirect.
Like I said though, I might be wrong.Thanks! So far I figured out that adding $withcomments=”1″ at the top of index.php does it – though not sure how that’s going to affect other views of the blog (category, individual, etc) – plus, I have to figure out how to not show the comments form.
I’m thinking of creating a second comments routine called wp-comments-no-form.php to output comments but without the form. But how do I only show this on the front index page?
How does WordPress know what kind of page it is showing? (front page, individual post, category, date-based archive… etc.)Been digging around in the variables of index.php. Seems like one way to tell that I’m showing the index/frontpage is to see if [REQUEST_URI] is equal to [SCRIPT_NAME] – does that make sense?
i don’t seem to be able to get this to work. i want to have the comments and comment form load onto my index.php file.
if (empty($_SERVER[‘QUERY_STRING’])) {
echo “YOU’RE VIEWING THE INDEX!”;
} else {
echo “NOPE!”;
}
where precisely am i supposed to put that?
and i assume i put this –
<?php
if (empty($_SERVER[‘QUERY_STRING’])) { // Query string empty?
$withcomments=”1″; // Show comments regardless.
}
?>
where the usual comments link would go.
help anyone?
thanks!bump!
well, i have found the solution for my own needs.
just in case someone else wants the same, and doesn’t understand these instructions, i’ll tell you what i did!
i want the comments and comments form to load on my index page.
so i made the first few lines of php on the page read thus:
<?php
/* Don’t remove this line. */
require(‘./wp-blog-header.php’);
$withcomments=”1″;
?>
simple. ??
that is what “at the top of index.php” means in case you are as un-nerdy as i.I had the same problem with WP 1.2.2. I modified my
wp-includes/template-functions-comment.php file as follows. This shows only the comments without the whole post form. I don’t know PHP so make sure you back up this file before attempting.!I changed the function: comments_popup_link. This is the function that shows the Comments(0) link. I modified it to show the same stuff that is shown on the Comment editing page. The only drawback is that a lot of stylesheets out there will show the comments left aligned so you may need to update your stylesheets. You can check it out on
https://nicksrecovery.com/index.php?m=20050125
To do it:
Step 1.
First edit line 61 from:
global $comment_count_cache, $single;
to:
global $comment_count_cache, $single, $comment;
2.
This should be placed at the end of the function comments_popup_link (around line 99) just before the closing bracket.
if($number > 0)
{
$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = "$id" AND comment_approved = "1" ORDER BY comment_date");
if ($comments)
{
//echo "<h3> Comments:</h3>";
echo "<ol id="commentlist">";
foreach ($comments as $comment)
{
echo "<li id="comment">";comment_text();
echo "<cite>";
comment_type();
echo " by ";
comment_author_link();
comment_date();
echo " @ <a href="#comment-";
comment_ID();
echo"">";
comment_time();
echo "</a>";
edit_comment_link(__("Edit This"), " |");
echo "</cite>";echo "</li>
";
}
echo "</ol>
";
}
}Maybe I’m stupid, but a simple answer to have WordPress 1.5 Show Comments (and optionally) with no Comment Form on the Front Page (index.php) has been extremely difficult to find. I think a lot of the problems have stemmed from some solutions not specifying the versions of WordPress they were using.
My solution uses a very simple solution:
STEP ONE:
Download this file.
Upload it to your plugins directory (/wp-content/plugins/)
Log in to the admin section of WordPress and click on the Plugins section and “Activate” the Plugin.https://www.meyerweb.com/eric/tools/wordpress/mw_comments_trackbacks.html
**IF YOU WANT THE COMMENT FORM TO APPEAR DON’T DO STEP TWO**
STEP TWO:Save the following code as a new .php file called: “comments-no-form.php”
How do you do this?
1. Open up Notepad
2. Copy and Paste all the code into Notepad
3. Save As “comments-no-form.php”Upload this new file to your current theme’s directory
(/wp-content/YOURTHEME/)**START OF CODE BELOW THIS LINE**
<?php // Do not delete these lines
if ('comments-no-form.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.
<?php
return;
}
}/* This variable is for alternating comment background */
$oddcomment = 'alt';
?><!-- You can start editing here. -->
<?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() ?>">
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Due to underwhelming spam, your comment is awaiting moderation.</em>
<?php endif; ?><small class="commentmetadata"><a>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></small>
<?php comment_text() ?>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?><?php endforeach; /* end for each comment */ ?>
<?php if(is_wpuser_comment() != 0) {echo "I'm a CTT Member. Are you one? Sign up on the right. ";} //official comments addition ?>
<?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">Sorry, you're too late. If you were here earlier, you could have posted a comment, but you weren't, so you can't.<?php endif; ?>
<?php endif; // if you delete this the sky will fall on your head ?>
**LAST LINE OF CODE IS ABOVE THIS LINE**STEP THREE:
This is the last step. Find this code or the closest thing to it, using Notepad, in your theme’s index.php file
(/wp-content/YOUR THEME/):**FIRST LINE OF CODE BELOW THIS LINE**
<p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
**LAST LINE OF CODE ABOVE THIS LINE**Underneath the above code and before the
</div>
enter the following code:**FIRST LINE OF CODE BELOW THIS LINE**
<?php $comments = mw_comments(); include(TEMPLATEPATH . '/comments-no-form.php'); // Display comments
?>
**LAST LINE OF CODE ABOVE THIS LINE****IF YOU WANT THE COMMENT FORM TO APPEAR CHANGE THE ABOVE FROM:
comments-no-form.php
TO
comments.phpSave this file and upload it back exactly where you found it.
I know that looks hard, but I promise you, it’s very, very, very simple. Because of the limited options on formatting this page, I tried to make this as easy to read as possible. I’m sorry if it’s difficult to understand. If you have any questions, feel free to email me – My email address is my username A T myrealbox D O T com (obviously replace at with the @ symbol and DOT with .)
Nihir:
Fantastic tutorial! I am new to WordPress, and know just enough to really wreck a web page. Your clear response has been a big help, works like a charm, and taught me quite a bit in just a few minutes a lot more about how WordPress works. Thanks again – I hope I soon learn enough to be so helpful to others!so what’s the procedure for WP 2.0?
The procedure for WP 2 is exactly the same. Thanks for a great tutorial nihir, it really helped me out.
- The topic ‘Show comments on front page’ is closed to new replies.