• Hi all,

    First off, I LOVE WordPress. It’s been a breeze to install, configure and get running. Two very enthusiastic thumbs up. Fine family fun.

    Anyway, I was wondering how you would go about adding the “comments” feature to non-Wordpress pages. Is it possible? I’ve custom written a number of pages which are quite complicated as is; all I want it to tack on the Comments feature at the bottom to allow people to remark on the page content.

    Any suggestions would be most appreciated! 🙂

Viewing 16 replies (of 16 total)
  • Okay, it was messy but I got it working. All the individual photo pages on my site now take comments. Check it out: http://kiramarch.com/photo.php?id=0208%20outside.jpg&tag=favorites

    (Yes, I know flickr does all this and more, but I wanted a more sophisticated tagging system than flickr supports, and I needed a project to learn php on.)

    The only thing I haven’t gotten working is the Ajax plugin (it’s still doing fine on my WP pages, though).

    Here’s what I had to do:

    Add to my DB structure
    – new table with my page ID and an autonumber
    – new ID field in my main data table. Uses a negative number corresponding to the autonumber in the translation table…this way it will never bump into WP posts and mix up comments.
    – auto-fill that new negative ID number each time I add a page

    change my page template to incorporate the comments
    – added calls to get_post (fills in the data wp needs to write the comments) and comment_template (displays and solicits the comments)
    – if i want to get ajax plugin turned on, must add the includes in the header by hand (I’m not using the wp header)

    Then in functions.php:
    – changed get_post to set global $id, since it has to be shared among more functions now
    – get_post handles the negative number fine, it turns out

    Changes to comment-functions.php
    – In comments_template function, added access to global $id and conditional so that it will execute with neg number
    – Also added a couple new cases so that it doesn’t look up negative IDs in the wp_posts table, since it won’t find anything.
    – In wp_insert_comment…put in one new condition that assumes comments are open on all photo pages.

    Then wp-comments-post.php, which is what the add a comment form calls
    – Skipped the status check if the ID is negative

    And finally, in comments.php:
    – Construct and pass optional redirect location because it won’t know what to reload on its own
    – Pointed a redirect to an anchor to make the reloading less annoying (until/unless I get the ajax plugin working)
    – Changed the comment section heading to static because it was looking up info about the posts. Static doesnt bother me, but I could have skipped it just for the hacked pages if I cared.

    All done!

Viewing 16 replies (of 16 total)

The topic ‘Adding “Comments” to non-WordPress Pages’ is closed to new replies.