Posting Source Code in WordPress, Take 2
In my searching, I have found another WordPress source code plugin, called wp-syntax. This one uses GeSHi, the Generic Syntax Highlighter. It features many languages, and is extensible to even more. (If I ever post a COBOL snippet, I’ll probably add COBOL support to it, and contribute it to the codebase.)
To use it, you simply put a pre tag, followed by “lang=[language]“. It will also do line numbering. Of course, with a single “language” parameter, the embedded language will not be highlighted as well. In this case, the previous plug-in works better; although the syntax highlighting has to be done manually, it can handle multiple languages.
Here is what the example from the “Category DropDowns in WordPress” post looks like with lang="php"…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php /** * This creates a list of category links that can be used with a category dropdown */ $aCategories = get_all_category_ids(); $iMaxCat = 0; foreach($aCategories as $iThisCat) { if ($iMaxCat < $iThisCat) { $iMaxCat = $iThisCat; } } $iMaxCat++; ?><div style="text-align:center;"> <form name="categoryform" action="" style="text-align:center;"> <script type="text/javascript"> var aLink = new Array(<?php echo($iMaxCat); ?>); <?php foreach($aCategories as $iThisCat) { echo("aLink[$iThisCat] = \"" . get_category_link</span>($iThisCat) . "\";\n"); } ?> function goCat() { window.location = aLink[document.getElementById('cat')[document.getElementById('cat').selectedIndex].value]; } </script> <?php wp_dropdown_categories('class=sidebardropdown&orderby=name&show_count=1&hierarchical=1'); ?> <br /> <button class="sidebarbutton" type="button" style="margin-top:5px;" onclick="goCat();">View Category</button> </form> </div> |
And, here’s what it looks like with lang="javascript"…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php
/**
* This creates a list of category links that can be used with a category dropdown
*/
$aCategories = get_all_category_ids();
$iMaxCat = 0;
foreach($aCategories as $iThisCat) {
if ($iMaxCat < $iThisCat) {
$iMaxCat = $iThisCat;
}
}
$iMaxCat++;
?><div style="text-align:center;">
<form name="categoryform" action="" style="text-align:center;">
<script type="text/javascript">
var aLink = new Array(<?php echo($iMaxCat); ?>);
<?php
foreach($aCategories as $iThisCat) {
echo("aLink[$iThisCat] = \"" . get_category_link</span>($iThisCat) . "\";\n");
} ?>
function goCat() {
window.location =
aLink[document.getElementById('cat')[document.getElementById('cat').selectedIndex].value];
}
</script>
<?php wp_dropdown_categories('class=sidebardropdown&orderby=name&show_count=1&hierarchical=1'); ?>
<br />
<button class="sidebarbutton" type="button" style="margin-top:5px;" onclick="goCat();">View Category</button>
</form>
</div> |
This is another option, and is probably what I’ll use for single-language posts, or posts where the embedded language may not be crucial.


DamionKutaeff said,
March 22, 2008 at 1:49 pm
Hello everybody, my name is Damion, and I’m glad to join your conmunity,
and wish to assit as far as possible.
dschibut said,
September 29, 2008 at 7:25 pm
I started this thread to evaluate public available web proxies:
Which are really anonymous?
Which can unblock facebook, myspace etc, in other words: are fresh ?
Which would you recommend?
Thanks for your help,
Dschibut
P.S.: In my country, the freedom of speech is somehow constrained, please give me a hint, if you are not sure about your recommendation.
HSCharles said,
November 16, 2008 at 12:49 am
I have a flash site
i’m looking for the script who makes google ads in flash.
can you give me the link?
loossevew said,
July 26, 2009 at 9:53 pm
Hello There!
Just wanted introduce myself.
Andreas here, and I from Singapore.
I read for a while here and want introduce me!
Thats all for now
Andreas!
Web Hosting Singapore
cubrikaska said,
October 3, 2009 at 3:52 am
Que pregunta muy buena
Poodoruidly said,
March 21, 2010 at 7:50 am
Your welcome everyone,
My PC worked not correctly, many mistakes and buggs. Please, help me to fix buggs on my PC. On format http://www.msn.com/ please.
My operation system is Windows XP.
Thanks,
Poodoruidly
VusualkVowPal said,
March 29, 2010 at 4:36 pm
Hi
I am a newbie here.
Glad to find this forum…as what I am looking for
ipdma said,
April 13, 2010 at 7:38 am
delivery – Стабильный доход.