January 19, 2013

http://500px.com/sinnedh

Please have a look at my gallery.

http://500px.com/sinnedh

Categories: Uncategorized

December 13, 2011

Snow is coming!

First snow in the Jura mountains…

Snow in the Jura mountains.

Categories: Photographs

October 15, 2009

Twig

New template language for PHP released.

Following the blog of Fabien Potencier, I’ve noticed, that he has written a new template language for PHP, which is called Twig. The syntax is based on the templating language of the Python Webframework Django.

Here is a very simple code example of a loop to get an impression, how it works:

1
2
3
4
5
{% for entry in entries %}
  - {{ entry.name }}
{% else %}
  No entry has been found.
{% endfor %}

Maybe this great new Sensio Labs tool will be part of Symfony 3!?

At least for Symfony 2 Twig won’t be the default template language. But it will become available as plugin, so that developers can use plain php templates as well as twig templates and mix both in one project.

Categories: PHP

September 21, 2009

Redirect to first child

How to use wp_redirect() in Wordpress to jump from a parent menu item to the first child item

On the last Wordpress page I have made, I had the problem, that I wanted to navigate automatically to the first child element in the menu and skip the parent menu element. Of course this is no problem, if I can create the menu, but here I used the corresponding wordpress template tag wp_list_pages(). Innately there is no possibility to configure it with the wished behaviour.

I have tried several ways to do this:

  • using the Wordpress redirection plugin
  • using apache’s rewrite module

But everytime I had the problem, that I was not flexible enough, when creating new menu items. By that I mean, that there was no way to separate the responsibilities between authors and administrators. Each time a new menu item was created by an author, he had to contact the administrator to change/add a redirection rule.

A more elegant way to achieve this redirection makes use of the Wordpress templating functionality. Each wordpress page is assigned to a template, which can be specified, if a customised template exists. One can create such a template, by creating a file in the theme folder, beginning with a php comment, which defines a “Template Name”. So, for example a very simple template which does nothing but prepending the timestamp on the top of a page, would look like the following code:

1
2
3
4
5
6
7
8
9
10
11
<?php
/*
Template Name: Show Timestamp
*/
echo date("F j, Y, g:i a");
get_header();
// ...
// add the rest of the default index.php here 
// ...
get_footer();
?>

So if we want to redirect a page automatically to its first child page, all we have to do is to create a template, which calls the function wp_redirect(). See the following code snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
  while (have_posts()) {
    the_post();
    $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
    $firstchild = $pagekids[0];
    wp_redirect(get_permalink($firstchild->ID));
  }
}
?>
Categories: Wordpress

September 20, 2009

Hello world!

Just installed Wordpress and created a minimal theme, hence this blog is ready to run.

I don’t know what will be the focus of this blog yet, but at the moment I’m working a lot with the PHP Framework Symfony and – of course – jQuery, the fabulous JavaScript library. Due to my side job at terrestris the chance is high, that I will also share some experiences with web mapping tools like OpenLayers or PostGIS. For the latter, I also recommend the weblog of my colleague Marc.

Categories: Uncategorized