<?php
query_posts(‘posts_per_page=1&post_status=publish&cat=1’);
if (have_posts()) {
the_post();
?>
<h2>Today's BLOG: <a href="<?php the_permalink(); ?>"><? the_title(); ?></a></h2>
<?php
the_content();
print '<h2> </h2>';
$withcomments = 1;
comments_template();
}
?>
</div>
<script type=“text/javascript”>
// Iterate through Blog reply inputs…
var control = $(’#block4 input:text’);
for (var x = 0; x < control.length; x++) {
if (control[x].id == 'email') {
control[x].value = '<?php print htmlentities($fst->fetch_parent_email($_SESSION['id'])); ?>';
} else if (control[x].id == ‘author’) {
control[x].value = '<?php print htmlentities($_SESSION['first'].' '.substr($_SESSION['last'], 0, 1)); ?>';
}
control[x].type = ‘hidden’;
}
control.parents(‘form:first’).append(’<input type=“hidden” name=“redirect_to” value=”<?php print $_SERVER[‘PHP_SELF’]; ?>?task=blogcomment” />’);
// Hide all of the labels for the above inputs
control = $(’#block4 label’);
control.css(‘display’, ‘none’);
- query_posts() finds the blog post we are interested in
- have_posts() ensures that we have one
- the_post() prepares it for our use
- the_permalink() is a link to the blog post on the blog
- the_title() is the post title
- the_content()—same idea
- comments_template() shows the comments (when $withcomments is set) along with a comment entry form, if your WordPress settings allow it.
Now comes the dynamic part. Because this was on a page that users had already logged in to, I decided to fill in the user’s name and e-mail address for them so that users can recognize each others comments. The h2 tag was a CSS hack to insert a dividing line between post and comments.
For reasons that I won’t name here, there was another text input that was named “email” so jQuery was used to find the correct correct HTML form items. “#block4” is the containing div and “input:text” is the text selector.
After it sets the text, it hides those controls. This leaves the labels visible. Thankfully, jQuery can handle this case as well, and easily. It only takes two lines (that could be merged) to hide all of the labels in the “#block4” div.
One more trick that is performed is to modify the comment form to redirect to the current page after a comment is posted. Surely you can think of a use for this. jQuery is very handy.
EDITTED: Typo.
Comments
Submitted by micaela on
I always wanted to know how to hack into a computer;)
Submitted by Chris on
The word “hacker” was originally for people who liked to dissect things and learn how they worked. This is a hack in that sense of the word.
Submitted by micaela on
thanks for the clarification;)