If you’re like me, running a blog powered by WordPress which you always need to show some programming codes in a number of languages, and you want those codes to be well-formatted with syntax highlighted while being displayed to your users. You can then make use of the WordPress’ Plugin, Wp-Syntax to do so.
The Wp-Syntax plugin is very easy to use. As usual, download it and add it into your /wp-conten/plugins/ folder. And activate it from the plugins section of your Administrative panel. So, you can simply highlight or wrap a block of text in your blog post which contains some programming codes by simply using the <pre lang=”LANGUAGE” line=”1″> .. your PHP code…. </pre>. The line=”1″ is optional which specifies whether you wanna show line numbers. Example as follows where I have some lines of PHP code wrapped by the <pre></pre>.
Example, wrapping PHP code using the <pre></pre> tag pair
<pre lang=”php” line=”1″>
<?
$res= mysql_query(“SELECT * from customer order by name”);
$nrows=mysql_num_rows($res);
if ($nrows>0)
{
for ($r=0; $r< $nrows; $r++)
{
$row = mysql_fetch_assoc ($res);
echo "<p> ".($r+1)."<b>Customer Name:</b>".$row['name']."</p>";
}
}
mysql_free_result ($res);
?>
</pre>
The result, beautifully formatted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <? $res= mysql_query("SELECT * from customer order by name"); $nrows=mysql_num_rows($res); if ($nrows>0) { for ($r=0; $r< $nrows; $r++) { $row = mysql_fetch_assoc ($res); echo "<p> ".($r+1)."<b>Customer Name:</b>".$row['name']."</p>"; } } mysql_free_result ($res); ?> |
0 Responses to “Wp-syntax plugin for WordPress to automatically format or highlight syntax on programming codes in your blog posts”