Is it just み?

Tag: Plugin

Zen Coding

by on May.03, 2010, under Computer

Nur ganz kurz. Interessant für alle die HTML per Hand schreiben und nicht mit irgend einem WYSIWYMGIYAL-Editor arbeiten (What you see is what you might get if you are lucky): Zen Coding

Zen Coding ermöglicht es nach einer kurzen Einarbeitungszeit (sehr kurz, wenn man CSS kennt) unheimlich schnell HTML-Strukturen zu bauen. Das Demostrationsvideo auf dieser Seite hat mich erst einmal umgehauen.

Mal sehen wie es sich im täglichen Gebrauch schlägt.

Comments Off on Zen Coding :, , , , more...

WordPress: Highlight PHP Code

by on Nov.22, 2009, under PHP, Programmierung, Technik

Ich werde mal versuchen einige meiner Einträge auf Englisch zu verfassen – um in der Übung zu bleiben.

I like to write about programming, and since I am using WordPress and writing plugins for it, PHP is the language of choice when it comes to blog-related development.

I wanted to put my PHP-Code into my entries and I wanted it to look nice, which means mono-spaced font and syntax highlighting. The first one was fairly easy to archieve by just changing the CSS. Whenever I put code into my blog, I write it between <pre> and </pre>, so I just had to change the CSS for the pre-element:

 pre {
    height: auto; 
    overflow: auto;
    color: #EEE;
    padding: 5px;
    margin: 10px;
    scroll: auto;
    font-family: Courier New, monospace;
    font-weight: bold;
    white-space: pre;
    font-size: 9pt;
    line-height: 10pt;

The highlighting however must be done on the server side by PHP, so I had to write another (in fact two) filter-function:


function highlightCode($content) {
    if (
false === strpos($content'<pre>')) {

$content preg_replace_callback(


highlightCodeCallback($matches) {
    if (
false === strpos($matches[0], '<?php')) {
$code $matches[0];
$code preg_replace(
$code strip_tags($code);
// Wordpress adds the space when saving
$code str_replace('<?php''<?php'$code); 
$code highlight_string($codetrue);
$code str_replace('/*§§BR§§*/'"\n\n"$code);
$code htmlspecialchars_decode($code);
$code str_replace('<?php''<?php'$code);

'<pre>'$code .'</pre>';
Comments Off on WordPress: Highlight PHP Code :, , more...

WordPress: Filter certain categories on main page

by on Nov.20, 2009, under PHP, Programmierung

Ich werde mal versuchen einige meiner Einträge auf Englisch zu verfassen – um in der Übung zu bleiben.

I am using the Twitter Tools plugin to automatically create Tweets for my blog entries and vice versa to have some kind of tweet archive on my blog. That works flawlessly.

The only problem is: I tweet too much. I only want to show five entries on my front page, which basically means, that my last real blog entry is gone after one or two days, because of the twitter entries. The solution: Entries from the Tweets category should not be visible on the front page.

I had to extend my my-blog-exclusively-plugin with a function that filters the posts that appear on the front page, for this I added a filter to the hook “the_posts” which is called quite early in the loop before anything has been done to the posts. The posts that would be shown on the front page are given to the callback-function as first parameter in the form of an array. Here is the code:


// Filter post from the category Tweets on front page
); /**/

function filterTweets($posts) {
// Filter only on the front page!
if (!is_front_page()) {

$tweetCategoryName 'Tweets';
$numVisiblePosts 5;

$postsToShow = array();
$filteredPosts = array();

$num 0;
    foreach (
$posts as $post) {
$cats in_category($tweetCategoryName, (int) $post->ID);
        if (!
$cats) {
$postsToShow[] = $post;
        } else {
$filteredPosts[] = $post;

        if (
$num >= $numVisiblePosts) {

    if (
$num $numVisiblePosts) {
// Too many twitter posts... what the hell... show some of them
$numTwitterPosts $numVisiblePosts $num;
$postsToShow array_merge(


Another thing I had to do was increase the number of posts shown on the front page, since my plugin now handles restricting the number of posts and I have to ensure that my function gets at least some posts that are not tweets. (But even if there are not enough, it fills up the front page with twitter posts.)

Comments Off on WordPress: Filter certain categories on main page :, , , , more...