May 2, 2005 Nomadig, WordPress:

Commenting in reviews section

Now all reviews under travel / reviews section have commenting possibility. This change was made to serve better those visitors that find the site through search engines, and who do not venture to the journal to comment the article.

Regarding technology, I spent better part of the weekend figuring out how to bend WordPress arm to allow using its template capabilities outside the journal section.

First and foremost, I had a huge problem of launching the template. The template selection has a hook, but you cannot insert anything to that hook outside WP code, as the function for adding hooks is not yet defined — it will be included later. I solved this by adding the function directly to the correct array (found out by reading the source).

Now the correct template file was used, but it couldn’t show any posts. It showed the title of the post on the browser title bar, but the post itself was not shown. I couldn’t figure out why and had to back out.

The next solution was to introduce a new variable in the Reviews’ PHP code and change the template’s index.php to launch another file when this variable is set. Now the reviews.php includes WP if the user requests for a single review. This worked fine and I could concentrate my efforts to make the new file inside the template directory to show reviews properly. That wasn’t hard.

Then I added comment form through normal WP template function call. This was successful, except that I couldn’t easily get rid of the trackback text. I summoned yet another ugly PHP hack to check whether that line should be printed or not.

Now the whole page looked good and I could add comments without big problems. Only small problem of sending me back to journal after adding a comment persisted. I had to comment a couple of lines in wp-comments-post.php to make the HTTP redirect to return to the original page.

The last issue was that I’ve added some elaborate and nice looking error messages in the commenting process and those wouldn’t work. The used cookies were bound to /journal/, so there were not send to /travels/reviews.php. Another change in wp-comments-post.php and problem was solved.

Finally the thing was ready. As I couldn’t find any issues after an extensive test period, I decided to launch it right away. First, of course, I had to remove a bunch of dead code that was used in the earlier versions to show the single review.

Hopefully you find the commenting possibility useful.

Comments

The URI to TrackBack this entry is: http://www.nomadig.com/2005/05/02/commenting-in-reviews-section/trackback

No comments yet.

Leave a comment

The following Textile shortcuts are available:

_emphasis_
*strong*
@code@
^superscript^
~subscript~
+inserted text+

Hyperlink:
"link text":http://link.url

Image:
!http://image.url!

Lists:
* bulleted
# numbered

Hide help

Please be polite and use common sense when posting. Any comment is subject to removal. The e-mail address is required, but it is not shown to anybody else than the administrator.

Commenting uses Textile and your message is previewed below. Show Textile help

Write your comments

 

Preview

1.  — Jan 6 2009