• hey,

    i found a code snippet for last comments on a static page:
    but i use comments only with a pop-up.

    <?php comments_popup_link('0 Comments', '1 Comment',
    '% Comments', 'comment-link-top', 'Comments closed.'); ?>

    could anyone help me to use the pop-up-link above in the code?
    that would be great πŸ™‚

    <?php
    $comments = get_comments('status=approve&number=5');
      foreach($comments as $comment) :?>
    
      <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 
    
        Who: <?php echo($comment->comment_author);?><br />
        About: <a href="<?php echo get_permalink($my_id) ?>#comment-<?php echo $comment->comment_post_ID?>" title="on <?php echo $title ?>"><?php echo $title ?></a><br />
        What they said: <?php echo($comment->comment_content);?><br />
        When they said it: <?php echo($comment->comment_date);?><br />
    
      <?php endforeach;?>
Viewing 15 replies - 1 through 15 (of 16 total)
  • Moderator bcworkz

    (@bcworkz)

    The pop up link does not go in the code, rather the code goes on your comments-popup.php template. Depending on what your template does, it may be better to tweak that than replace it wholesale with this snippet.

    Your pop up link can stay where it is.

    Thread Starter mrfraz

    (@mrfraz)

    Hm. but how can i open the popup, when i clicked on

    <a href="<?php echo get_permalink($my_id) ?>#comment-<?php echo $comment->comment_post_ID?>" title="on <?php echo $title ?>"><?php echo $title ?></a>

    can you help me with the code?
    that would be great.

    Moderator bcworkz

    (@bcworkz)

    Um, now I’m not sure what you’re trying to do. Based on your first post, I assumed you had a functioning comment popup feature that shows all comments for a post. You want to alter that so one only sees the 5 most recent comments for a post.

    Your last post makes me believe you want to build a link that invokes a popup for a single comment from which you’ve already determined the comment ID somehow.

    Please describe in detail where these links invoking a popup are to appear and exactly what is to be displayed in the resulting popup. Once I am clear about what you are trying to do, I think I can help you in general terms on what to do. I would not be able to provide working code for you. I may provide example snippets or simple tweaks to existing code, but I do not write code for people, sorry. I will try to help you within those constraints.

    Thread Starter mrfraz

    (@mrfraz)

    Hey,

    thanks for your Help.
    I want the five or ten recent comments with title and onlick the popup with comments. that’s what i need. not a link to the single page (my website work without single-page) rather the link to the (pop-up)-comments.

    thank you very much πŸ™‚

    Moderator bcworkz

    (@bcworkz)

    OK, I get most of what you want, except exactly what is displayed and how in the popup. As the script stands, the echo get_permalink($my_id) would normally link to the entire single post with comments. Sounds like your theme is different, you get what you normally get when you click on any post permalink. I don’t think that’s what you want. Or is it?

    You could substitute echo get_permalink($my_id) with your normal comments_popup_link() to get all the comments in one popup, or whatever you normally get now. It may be possible to tweak this so the links are skip links so the same page opens in the popup, with the page scrolled so that the clicked comment is at the top of the window. The user could scroll up or down to see the other comments. Is this what you want?

    Or do you want just a single comment in the popup? The user closes the popup and clicks another comment to see another comment in a new popup.

    Or something else? Like the parent comment and all of it’s reply children for any click in the family?

    When I said I want details, I was serious πŸ™‚ Each variation calls for a very different approach.

    Thread Starter mrfraz

    (@mrfraz)

    Page: Community

    20 Recent Comments

    Topic: Arsenal London wins
    From: User #1 | at 4:00pm

    Topic: Machester City wins
    From: User #2 | at 3:00pm

    Topic: FC Barcelona wins
    From: User #3 | at 2:00pm

    ..

    And wenn you click on Arsenal London wins, should open the popup with the Comments from this post. That’s what i need. Only Comments…or popup-link..

    Thank you for your good feedback.

    Moderator bcworkz

    (@bcworkz)

    Thank you, that confirms I correctly understood what your post page would look like. I wasn’t sure what you wanted in the popup itself though. Sounds like you want all comments for the post.

    Isn’t this what you have now, other than you only have a single link for all comments? So now, you can simply use comments_popup_link() repeatedly, varying the link text with the title of the current comment in the loop. Working off your initial snippet listing the 5 latest comments, you’ll need to rework the Who What When into your From | at format. Rework the About: line into something like this:
    Topic: <php? comments_popup_link('', $title, $title, 'comment-link-top', ''); ?>

    Thread Starter mrfraz

    (@mrfraz)

    <?php
    $comments = get_comments('status=approve&number=5');
      foreach($comments as $comment) :?>
    
      <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 
    
        Who: <?php echo($comment->comment_author);?><br />
        About: <?php comments_popup_link('', $title, $title, 'comment-link-top', ''); ?>
        What they said: <?php echo($comment->comment_content);?><br />
        When they said it: <?php echo($comment->comment_date);?><br />
    
      <?php endforeach;?>

    didn’t work? About ist blank…

    best!

    Moderator bcworkz

    (@bcworkz)

    It should only be blank if there are no comments. You mentioned your theme does not use single pages, but the popup link uses the current post ID in the loop to decide how many comments there are and which title version to use. I believe it is choosing an empty title ” because it thinks the supposed current post has no comments.

    I suspect where you placed this script is not actually in a post loop, so you may need to fool the popup link function into thinking the current post is the post ID in $my_id. It’s hard to know for sure what’s happening without being able to run tests on your site, but try inserting the following after the $my_id assignment line and before the Who: line:
    <?php global $post;
    $post = $my_id; ?>

    This may mess up your normal post display, but if comment links show up, it will at least confirm what the problem is. If it does mess up your posts, I have a fix in mind. If it does not mess up your posts and shows comment links, you should be good to go with this addition.

    Thread Starter mrfraz

    (@mrfraz)

    Hey,

    i use a single Page called Community, where the last 10 Comments should be displayed. And the Topic should Link to a Pop-up with Comments releated to the topic. Or the pop-up-comment.

    Is that possible?

    The Code-Snippet above do this, but without.. the pop-up. Link only to the Single Post.

    Thanks for your help. Maybe we will find a solution πŸ™‚

    Moderator bcworkz

    (@bcworkz)

    The get_comments() function does not support taxonomy and category arguments AFAIK, so a different approach may be required to get comments of a particular topic. The best approach would be to directly query the DB using $wpdb methods, unfortunately I’m weak on mySQL queries, so I’m not much help with that. I only know enough to be fairly certain it can be done.

    A possible brute force alternative would be to accumulate all the topic post IDs into an array and pass that array as a ‘post_id’ argument to get_comments().

    It’s strange you are getting post links instead of popup comments, I did test the script in order to come up with the $post trick. I got popup comments on my installation, but of course we are using different themes. The only thing I can think of is your header template file is missing the required call to comments_popup_script(). Or your page does not use a header template? It can be called almost anywhere actually, though it’s usually called during the <head> section output. You could try calling it in your comment script above the foreach line and see if that helps.

    I hope this gets us closer to a solution, as I’m running out of ideas on what the problem may be. You should be getting popup comments, although from any topic for now.

    Thread Starter mrfraz

    (@mrfraz)

    Hm… i use this comments_popup_script()

    It works on the frontpage,
    but recent comments works not…

    do you have a code snippe for recent comments with

    title (link to comment pop-up)
    author
    and time?

    they i will try this one.

    best!

    Moderator bcworkz

    (@bcworkz)

    This is the test script I used that generates 5 title links and each link results in a popup comments window, albeit with all the post’s comments. It will take more coding to figure out how to skip down to the actual comment, if that’s what you want, but this first part needs to be working before anything is attempted with skip links.

    <?php $comments = get_comments('status=approve&number=5');
    foreach($comments as $comment) :?>
      <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;
       global $post;
       $post=$my_id;
       comments_popup_link('', $title, $title, 'comment-link-top', ''); ?>
    <?php endforeach;?>

    Thread Starter mrfraz

    (@mrfraz)

    works perfect, thank you very much.
    could you even insert date and author for me?

    that would be awesome… i’m not a php coder.
    i only need the ouput..

    thank you πŸ™‚

    Moderator bcworkz

    (@bcworkz)

    Here ya go…

    <?php $comments = get_comments('status=approve&number=5');
    foreach($comments as $comment) :?>
      <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;
       global $post;
       $post=$my_id; ?>
       Who: <?php echo($comment->comment_author);?><br />
       About: <?php comments_popup_link('', $title, $title, 'comment-link-top', ''); ?><br />
       When: <?php echo($comment->comment_date);?><br />
    <?php endforeach;?>

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘get last comments | with pop-up link’ is closed to new replies.