
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Have you found yourself wanting to display a piece of code in your blog post or a comment form that left you stripping off elements or re-pasting it over and over only to find that the code is actually being executed? I run in this issue a lot while replying to support questions, so I conveniently remove the “<” and “>” of all HTML tags and PHP scripts to allow the codes to to be displayed without execution, this however cause more harm than help to the novice user and the experience is never that pleasant. Help is finally here!
A combination of using the “code” tag and converted the base code by using converters like Postable makes for a delightful toll that allows users to share, copy and paste codes without any hassles and guesswork. Here’s how you go about it.
In order to demonstrate how it works, I have copied and pasted a piece of code from one of our latest themes below using Postable conversion:
<?php if (have_posts()) :?>
<?php $postCount=0; ?>
<?php while (have_posts()) : the_post();?>
<?php $postCount++;?>
<div class="entry entry-<?php echo $postCount ;?>">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="meta">
Posted <?php the_time('m.d.Y'); ?> at <?php the_time('g:i a') ?> in <?php the_category(', ') ?><?php if (function_exists('the_tags')) { ?><?php the_tags(', ', ', ', ''); ?><?php } ?> received <strong><?php comments_popup_link('Have your say »', '1 Comment »', '% Comments »'); ?></strong>.
</p>
The code is then displayed in a format that can be copied and pasted and never executed. Works fine to me!
Update: Two other tools of significant use are SimpleCode by Dan Cederholm which I have adopted as part of the comment form on this site and elsewhere and the user submitted Asciible converters!
April 2nd, 2008 at 8:59 am
Hey - I just went live with my own version of an ascii encoder as well. It uses regular expressions on the client side, so it is extremely fast. It also provides several options for customizing the output. Let me know what you think!
http://www.jeremymartin.name/projects.php?project=asciible
November 6th, 2007 at 4:36 pm
hi