ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using Edit Comments plugin within a query

January 07, 2009 11:27am

Subscribe [2]
  • #1 / Jan 07, 2009 11:27am

    judin

    54 posts

    Hello

    Last week, I was very kindly assisted with a project I’m working on, and I’m back to see if anyone can assist once again.

    All users to my site are registered and logged in. When they visit an entry, they are shown either a comment box if they have not left a response to the current entry, or what they have posted previously for that entry (therefore, they can only post one response per entry and only ever see their own responses). This thread has full details on this.

    I’m trying to use the Edit Comments plugin, to allow a person to edit their entry once they’ve posted it - but it doesn’t seem to work within the query of the single response. Does anyone have any ideas?

    I’ve also tried doing an embedded entry with any amount of code and just can’t achieve what I’m looking for. (Note, I am using the comment tag as the_comment as per the single response code above - might this be effecting the outcome?)

    Thank you!
    Justin

  • #2 / Jan 08, 2009 8:49am

    judin

    54 posts

    Bump (gentle push to the top…)

  • #3 / Jan 08, 2009 9:14am

    Mark Bowen

    12637 posts

    Hiya,

    Sorry meant to post this the other day. This should hopefully help. Follow all the instructions as per the plugin documentation to the letter and then just change your comments page template code to this instead :

    {exp:weblog:entries weblog="default_site" disable="member_data|trackbacks|pagination|categories|category_fields"}
    {exp:query sql="
    
    SELECT comment as the_comment, comment_id, comment_date FROM exp_comments
    WHERE weblog_id = '1' AND site_id = '1' AND status = 'o'
    AND author_id = '<?php echo $author_id; ?>' AND entry_id = '{entry_id}'
    ORDER BY comment_date DESC LIMIT 1"}
    
    You posted the following response to this task. You last edited this on {comment_date format="%d %F %Y at %G:%i"}.
    
    {exp:edit_comments:wrap_comment comment_id="{comment_id}" author_id="{author_id}"}
    {the_comment}
    {/exp:edit_comments:wrap_comment}
    
    {exp:edit_comments:edit_link comment_id="{comment_id}" author_id="{author_id}"}
    <div class="posted">[{text}Edit Comment{/text}]</div>
    {/exp:edit_comments:edit_link}
    
    {/exp:query}
    {/exp:weblog:entries}

    Note you need to have the {exp:edit_comments:javascript edit_link='site/edit_comment'} tag in the head of that page for it to work. The main parts that were stopping this from working were two-fold. Number one being yes you were right that as it is now {the_comment} instead of {comment} you need to reflect that in your code but also the most important one is that you need to bring back {comment_id} from the SQL query in order for the plugin to be able to use it.

    That should do it for you hopefully.

    Best wishes,

    Mark

  • #4 / Jan 08, 2009 12:05pm

    judin

    54 posts

    Hi Mark,

    Thanks for your reply. I did try that originally but test again just in case. As soon as you put the edit comment code in the query, it doesn’t work.

    Perhaps something conflicts? I have no idea what, though…

    Justin

  • #5 / Jan 08, 2009 12:40pm

    Mark Bowen

    12637 posts

    Make sure you definitely have the SQL query exactly as I have shown above. The most important part being this line here :

    SELECT comment as the_comment, comment_id, comment_date FROM exp_comments

    You need to make sure you have comment_id in there or it won’t work.

    Best wishes,

    Mark

  • #6 / Jan 08, 2009 1:29pm

    judin

    54 posts

    Sorry, I tried with your code, and it still doesn’t work. What happens for starters, is that a div around {the_comment} doesn’t get named, which I think is required for this to work.

  • #7 / Jan 08, 2009 2:03pm

    Mark Bowen

    12637 posts

    The full template codes that I used to test this are shown below :

    Hopefully this will help out a bit.

    Latest Comment Template

    <html>
    <head>
    <title>Your Latest Comment</title>
    {exp:edit_comments:javascript edit_link='site/edit-comment'}
    </head>
    <body>
    
    <?php
    global $SESS;
    $author_id = $SESS->userdata['member_id'];
    ?>
    
    {exp:weblog:entries weblog="default_site" disable="member_data|trackbacks|pagination|categories|category_fields"}
    {exp:query sql="
    
    SELECT comment as the_comment, comment_id, comment_date FROM exp_comments
    WHERE weblog_id = '1' AND site_id = '1' AND status = 'o'
    AND author_id = '<?php echo $author_id; ?>' AND entry_id = '{entry_id}'
    ORDER BY comment_date DESC LIMIT 1"}
    
    You posted the following response to this task. You last edited this on {comment_date format="%d %F %Y at %G:%i"}.
    
    {exp:edit_comments:wrap_comment comment_id="{comment_id}" author_id="{author_id}"}
    {the_comment}
    {/exp:edit_comments:wrap_comment}
    
    {exp:edit_comments:edit_link comment_id="{comment_id}" author_id="{author_id}"}
    <div class="posted">[{text}Edit Comment{/text}]</div>
    {/exp:edit_comments:edit_link}
    
    
    {/exp:query}
    {/exp:weblog:entries}
    
    </body>
    </html>

    This is accessed by a URL of this type :

    http://www.example.com/tests/latest-post

    Also note the {exp:edit_comments:javascript edit_link='site/edit-comment'} in the head of this template.

    Then I have a template called edit-comment in my site template group with this code in it :

    {exp:edit_comments:ajax_processing}

    If I then view the main template I get the comment and an edit link beneath it. Clicking the edit link makes a form field come up where I change the comment and can then save it.

    Hope that helps a bit?

    Best wishes,

    Mark

  • #8 / Jan 08, 2009 3:47pm

    judin

    54 posts

    Mark, you star!

    The annoying thing is, I’m sure I did exactly the same as what you’ve written here… but when I did it, it wouldn’t play ball.

    The code above is good to go (and I’m sure many others can think of uses for this too!).

    Thanks very much (there will be more random queries on the way, I assure you..!)

  • #9 / Jan 08, 2009 5:34pm

    Mark Bowen

    12637 posts

    Excellent news. Glad it’s all working now.

    Yep it is a quite elegant solution isn’t it. I’m going to have a look at using something like this on a site I’m making too 😉

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases