• Currently, if a visitor posts a comment, they’re redirected to the post itself. This usually means that they’ll end up at the TOP of the page, which is very likely NOT where their comment is. IMHO, this is a bug (I’d file a report + fix on Mosquito, but somehow it barfs on the database connection), or at the very least an inconvenience: I’d expect to be taken to my comment (which is what, for example, PHPBB does — not that I’m PHPBB’s biggest fan, but a lot of people use it and are used to it’s behaviour).

    Luckily, the fix is very easy.

    1. Open wp-comments-post.php (in the wordpress “root” directory)
    2. Locate the last line of code (in my install it’s line 55, which says “header(“Location: $location”);”)
    3. Change it to: header(“Location: $location#comment-“.$wpdb->insert_id);
    4. Save, and congratulate yourself on a job well done. =]

    How do others see this issue, anyway? Is this a bug, or am I just being quirky here? In other words, if Mosquito comes back up, should I file a bug, or a request, or shouldn’t I bother at all?

Viewing 8 replies - 1 through 8 (of 8 total)
  • One vote for quirky.

    If someone is posting a comment that means they must be on that themes single.php (it goes by various names dependent on designer) page.

    Lets assume that person is redirected to somewhere else than that comments page. Will that person know if his posting actually appeared? Did it disappear? Go to moderation?

    No he will again have to locate that page.

    A very good reson to have a “home link” on your single.php page.

    hmm, i don’t think you understood what dille was talking about Marc. He’s just redirecting to the bottom where the comments are instead of to the top where the post is. Pretty reasonable I’d say, so that they can see their comment and know it went through.

    Maybe you are correct and I misread the post, but jeebus how long of an entry must one have for this to be a major problem. A copy of War & Peace as an entry I concede it would create difficulties.

    On a normal length post, sorry, still vote quirky.

    I wouldn’t call it a bug as such, but I don’t think you’re “quirky” either. In fact, thanks for the “fixitup”….

    Thread Starter dille

    (@dille)

    @marc: an entry doesn’t have to be all that long — just had a look at your site, for example the “Sometimes you ask why”-post, and really, I can’t see any comments when I’m at the top of the page. Maybe you have a big-ass screen in front of you, but this laptop has a pretty standard 1024×768…

    Apart from that: after a couple of comments, everybody has to scroll — even if one of the comments _was_ made by Tolstoy.

    Not that that means that I’m not quirky, of course =]

    You can achieve a similar result without hacking the core files:
    https://www.ads-software.com/support/topic.php?id=29260

    Sorry for bumping this old topic, but I figured it’d be better than creating a new one.

    I’d like to do this on my blog as well, but I don’t see that line of code in my wp-comments-post.php file. I’m using 1.5.1.3 so I’m assuming this was originally written for an older version? How can I achieve the same thing on the version I’m using? Thanks.

    Thread Starter dille

    (@dille)

    (boing)

    Moshu: it’s not really the same. The method described there is about creating a link that’ll take you to the comments box when clicked. I want to be taken to my own comment (or at least the start of the comments) automagically after I’ve posted a comment.

    @BebiRoxors: Yes, the fix was for an older version. In case you didn’t have it solved: the method was changed. Now, you can specify a “redirect_to” parameter (using a hidden input) which the script will jump to after doing it’s thing. If the parameter isn’t supplied, it jumps to the referrer (IMO that’s a bad thing — not all browsers will specify a referrer, or not a correct one, but that’s another matter).

    Simply change
    wp_redirect($location);

    to
    wp_redirect("$location#comments");

    or to
    wp_redirect("$location#comment-$wpdb->insert_id");

    …if you want to jump to the comment that was just posted. Note: if the comment wasn’t posted, or if it hit the moderation queue, it’ll jump to a non-existent anchor, which means no jumping.

    Of course, you could go all groovy and change the template to include an anchor (let’s say #lastcomment) right before the last comment, and jump to that. That’ll always work, or at least until the next WP upgrade.

    edit:
    Aw, heck, it’s a simple hack anyway…

    1. Inside the comments loop (usually right after the <li> element, but this may not be the same across themes), before the name and comment and everything, you add this line:
    <?php $commentcount++; if ($commentcount == count($comments)) echo '<a name="lastcomment"></a>'; ?> (all on one line)
    2. Have the comment-post script redirect to “$location#lastcomment” (see above)
    3. Feel totally groovy. At least until the next upgrade…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Redirect users to their just-posted comment’ is closed to new replies.