30 May 2006 prla   » (Apprentice)

Wordpress Tinkering Reloaded

Hacked away some more on Wordpress this evening and I think this is as far as I’ll go for the time being, considering I’ve finished implementing what I’ve always wanted to have in the first place.

Building upon last night’s modification, I’ve now extended the DokuWiki parser in a way that it picks up the titles of existing pages (listed on the sidebar) and links appropriately back to them, in effect allowing me not to bother with explicit linking. So, say, if I have a page about Apple, which I actually do, everytime I mention it, it’ll get automagically linked to my own personal page about it. Like it just did.

The hack was unreasonably simple and that’s a testament, again, to DokuWiki’s awesome codebase, its parser being particularly well laid out. All I had to do was write the following almost trivial function and call it in the right place inside parser():

function wp_pages(&$table,&$text) {
  extract($GLOBALS);
    
  $pages = $wpdb->get_results("SELECT id,post_title FROM $wpdb->posts " . 
			       "WHERE post_status = 'static'");

foreach($pages as $page) firstpass($table,$text,'/('.$page->post_title.')/s', "<a href="?page_id=".$page->id."">1</a>"); }

All we do is retrieve all page titles from the database and swap their occurrences in the text with their respective HTML links, using DokuWiki’s own firstpass(), which does exactly that. So far I tried to break it in many ways but to no avail, which is a good thing.

Enough Wordpress/DokuWiki hacking now, let’s move on to other things :)

I’ve also added a couple more pages (you can access any of them from the sidebar on the right) and images illustrating a few of them (take for example the Ruby on Rails or Photography pages). Now that I got the basic infrastructure laid out for easily adding structured content to the site, expect an increase in the number of pages in the near future. Hopefully something will also be of interest to you and not just to me.

#

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!