Simple Media Queries Tester

CSS Media Queries are getting more popular and the adjustment of the size of a website for different clients or the size of the browsers are more necessary. The Media Queries are a solution, which also have its advantages and disadvantages. It was a disadvantage, when using, that I couldn't see all sizes at the same time. So why not just a small script, the iframe element. If you like to use it, here is a simple solution or you can use the current script in my "Test-Laboratory".
Continue reading …

Add Menus to the Admin Bar of WordPress

The new WordPress admin bar facilitates the access of backend and frontend to areas of the back end. Of course, this new control element of WordPress is expandable and can be adapted to the needs of the user. In some areas and for various needs, quick access to different areas is certainly interesting.

The newly created menus can be adapted as usual rights to the appropriate roles. A small example will demonstrate the integration.
Continue reading …

Control WordPress Nav Menu via Custom Fields

WordPress 3.0 also includes the menus, in addition to a number of other new features. Normally you generate a menu automatically by creating pages, but under Appereance / Menus you can create your own menu and assign a place where it replaces the normal menu.

But whoever currently uses WordPress as a CMS and blog (like me) may now have a problem: If you look at the blog you should be able to see the normal pages in the navigation, but if you then select a page with many subpages it would be nice if the subpages were listed in the menu bar as well as listing only one entry "Blog" which brings you back to the blog page.

Conveniently, WordPress already includes everything you need to put together this idea. They are on the one hand of course the aforementioned menus, and on the other side there are Custom Fields. If you have not hidden, you can find at every post and every page an editor where you can enter meta data. Via this meta data and with the help of a small code snippet you can control what is displayed in the menu.

You can put the code snippet in your functions.php of your Theme or in a Plugin.

//Filter the arguments for the wp_nav_menu_function to include a custom menu on pages.
function nr_2010_wp_nav_menu_args($args = '')
	if ( is_page() ) //custom menus only on sites
		global $post;

		$menu_name = get_post_meta($post->ID, 'menu_name', true);

		if( !empty($menu_name) && is_nav_menu($menu_name) )
			$args['menu'] = $menu_name;
	return $args;
add_filter( 'wp_nav_menu_args', 'nr_2010_wp_nav_menu_args' );

This code puts a filter on wp_nav_menu_args, these are the parameters of the function wp_nav_menu, which the Theme uses to output the menus.

As long as we are on a page (is_page()) the custom field menu_name will be used. If it's not empty and it has a menu with this name, the paramaters of this call will be modified, so it shows the right menu.

Only one thing left: Provide the correct meta data to the pages and create the corresponding menus. The menu editor is very intuitive, it shouldn't be a problem. Just a hint: It doesn't save automatically. 😉

Guest Post

This post was written by Niklas Rother - and is a post in our Advent Calendar Series on WP Engineer about WordPress.
Thank you very much from my part to Niklas.
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!

The WordPress Exif-Meta-Datas

WordPress stores when uploading files, some data in the meta data - the metadata. If there are pictures involved and these files contain EXIF data, then it outputs some EXIF data which can be used. For example, as additional information about the picture in a photo blog.

No matter what, and how you want to do that, here is a small function that reads the Exif data.
Continue reading …