Displaying a portion of Wordpress custom menu

Wordpress custom menus are a very valuable feature, as they allow creating hierarchichal menus in the backend. Sometimes it would be useful to just use portions of this menu, e.g when displaying a submenu on a page, containing links to the children of the currently selected parent page in the main menu. Unfortunately Wordpress does not yet provide a simple option for displaying just the children of a particular menu item, so a little more effort is needed to accomplish this task.

Figure out the parent page’s ID

 $post_root = 0;
 $p = $post;

 while( $p->post_parent != 0){

   $p = get_post( $p->post_parent );
   $post_root = $p;
 }

 if($post_root == 0)
  $post_root = $post;

Get a list of the post root’s children

 $children = get_pages( array('child_of' => $post_root->ID ) );

Define a custom Walker which will be used to iterate the menu

 class ChildMenuWalker extends Walker_Nav_Menu{

  protected $child_ids = array();
  protected $exclude = -1;

  function __construct($children, $exclude){

   $this->child_ids = $children;
   $this->exclude = $exclude;
  }

  function start_el(&$output, $item, $depth, $args){

    if( ! in_array($item->object_id, $this->child_ids) ){
     return;
    } elseif( $item->object_id != $this->exclude) {
     parent::start_el(&$output, $item, $depth, $args);
    }

   }
 }

the “start_el” function checks wheter the current item is in the children list. If so, the default Walker’s functionality is used, otherwise nothing is done (output remains empty). Pay attention to use $item->object_id, as this is the post object’s id.

Display the menu with wp_nav_menu using the custom walker class.

 wp_nav_menu( array(

  'menu' => 'main-menu',
  'walker' => new ChildMenuWalker($children_ids, $post_root->ID )
 ) )

This renders a menu, containing only the child elements of the selected post root.


Flash Android to HTC HD2

The HTC HD2 still is a great smartphone, the only drawback is, it runs Windows Mobile 6.5, which is outdated and much less flexible than Android. To get an idea about how the phone looks and feels running Android, one can place an Android build to the SD card and run it from there. At android.hd2roms.com a list of the most recent Android builds can be found. Some are SD ROMS which can simply be put to the SD card and some are NAND ROMS, which have to be flashed to the device.

SD ROMS

Download a build that suits you and place it inside the root folder of your SD card. The folder should contain a file “clrxad.exe” and “haret.exe”. First execute the clrxad.exe file. You actually don’t see anything happen here, this is normal. Then execute the haret.exe file. Your phone will reboot and boot into Android. First startup might take a while. When you shut your phone down again and reboot, it will boot Windows Mobile as usual.

NAND ROMS

To flash Android to your mobile phone’s ROM a little more effort is needed. Note that this can break your device, so you do it at your own risk!

Note that your Windows Mobile , SMS and contacts will be removed. In a future post I will show you a nice and easy way to export your contacts, so you can import them into your Android.

In order to be able to flash a new ROM to your device you need to install HSPL. Without HSPL you could ony flash signed ROMs for your device, e.g if your phone is T-Mobile branded, you could only install official T-Mobile ROMs. The most recent HSPL version is HSPL4 and can be found here.

Installing HSPL

connect your device to your computer with active synch. Once the connection is established, run the Hspl4.exe on your PC and follow the instructions. Note that if you plan to flash Android to your Phone you have to select 2.08 HSPL in the menu. For more details about installing HSPL read on here.

Once HSPL is installed, you need to install MAGLDR, which is a bootloader. Basically you have to download a file, connect your phone to the PC and execute a Rom Update Utility contained in the downloaded folder. See here for step by step instructions.

FLASH ANDROID

You are almost done. Select a ROM you like (e.g from android.hd2roms.com ). There are different ways to flash the ROM (e.g from SD card etc.). The one described here is quite simple. Just make sure you download a ROM containing a DAF.exe file.

Shut your mobile phone down. Press the volume down key and hold it while you switch your phone on. The MAGLDR bootloader will be displayed. Connect your phone to the PC. Navigate to the menu entry “USB flasher”. You can navigat up and down using the volume up and down buttons. Then click the phone button (the left-most button). Wait until your PC has established the connection and execute the DAF.exe file. This will flash Android to your phone. Once this is done, reboot your phone and it will directly boot into Android.


Google Maps Custom Markers not clickable

Google Maps API easily allows to add custom markers to a map (see documentation here). Should you encounter the problem of your custom markers not being clickable, even though you set z-index to a very high value, the solution could be the following:

simply set the API version parameter in the Google Maps Api url to 3.3 .

The script url you include in your page to display a map would then look like this:

“http://maps.google.com/maps/api/js?sensor=true&v=3.3″

This resolved the issue for me.


Download and cache Google Map Tiles

As stated in the official Google Blog, Google Labs now added a way for users to store map data for a radius of about 10 miles on a user’s smartphone. That makes it possible to view maps without an Internet connection, which is particularly useful when no data connection is available or to expensive (for example when being abroad). Altough it makes some planning necessary (the user needs to know for which area maps are needed approximately) it is a very useful tool.


Conditional Comments in Javascript

Using the @ sign in javascript comments can cause an error in Internet explorer. A very good description of the so called conditional compilation of javascript can be found here.


Wordpress wp_page_menu home link problem with qTranslate plugin

A very useful function Wordpress offers for building a simple navigation menu is wp_page_menu. The ’show_home’ option in the function’s arguments allows to automatically include a link to the site’s home page in the menu. Many multi-language Wordpress sites use the qtranslate Plugin to present contents in different languages. When using the wp_page_menu function that should include a link to the home page on sites that make use of the qtranslate plugin currently developers are experiencing the problem the link to the home page does not take the current language into account.

A solution to this problem is to add a filter, that takes the currently selected language into account (e.g. in the functions.php):

add_filter( 'wp_page_menu', replace_home_link($menu) );

function replace_home_link( $menu ) {

 $lang = qtrans_getLanguage();

 $new_link = get_bloginfo('url').'/'.$lang;
 $home_link = get_bloginfo('url').'/';

 return str_replace('href="'. $home_link . '"','href="'.$new_link.'"', $menu);

}

The above function basically takes the menu string (complete HTML markup) and replaces the link to the home page with a link to the home page with the currently selected language. (NOTE: this example assumes you configured qtranslate to use links like http://www.foo/en/test)


Wordpress Problem with to long custom post type names

When using many different custom post types in Wordpress, for example when having to deal with big amounts of structured data, custom post type names can get quite long. I imported some data and automatically had them assigned to different custom post types. When wanting to output post contents, nothing could be shown. A look at the database revealed, that by default in Wordpress the post_type field in the posts table is a varchar(20)…

You have two solutions now, either change the post_type field size or use shorter custom post type names, if you can.


Fullscreen browser application in Kiosk Mode on a Windows-Terminal

When it comes to running a browser application in kiosk mode, or any other software on a terminal, special security requirements have to be met. There must be no way evil users could get control over the system. For applications running inside the browser this means:

  • Users should be detained from closing the browser window
  • Users must not be able to start or terminate any other application
  • It is wise to prevent users from navigating to unwanted URLs, e.g. away from your application

Even though you can start your browser in fullscreen mode, e.g. with “–kiosk” parameter for Google Chrome, you cannot configure it in a way to prevent users from closing it down and gaining access to the operating system. Additional software is required, to limit keyboard input and user permissions. Being compatible with most Windows distributions, Internet Kiosk Pro is a pretty good and highly customizable Software for public terminals.

Basically, the software allows to:

  • start the terminal in kiosk mode, with restricted access rights
  • disable keys
  • define shortcuts to programs or web-pages the users can access
  • set the kiosk’s appearance (show/hide windows taskbar etc.)
  • set security restrictions like disallowing downloads, hiding hard disks etc.

The software has a built-in safe Web-browser wich can be highly customized. You can limit the accessible URLs, start it in full screen by default, prevent users from closing the browser or adding new tabs or windows, hide navigation bars and border and more.

When all wanted options are set, the kiosk can be blocked. The system reboots in kiosk mode, with all security restrictions applied. The only way to gain control over the system when in kiosk mode is using a master-key-combination. By pressing a specific key-combination (can be set in the options) the administrator is presented an input field with username/password. Only after entering this credentials control over the system can be gained.

Limitations:

The built-in safe Web-browser cannot be customized in a way to completely hide the tab bar and the information bar. In case you need a full-screen application without any tabs etc. you have to use a different browser. With its fast javascript engine and advanced HTML 5 readiness Google Chrome is highly suitable for such applications.

As the browser’s behavior cannot be customized from within the kiosk software, more configuration has to be carried out by hand:

  • Start Google Chrome in full-screen mode by adding the –kiosk parameter to the shortcut, i.e. ‘path/to/google_chrome/chrome.exe –kiosk. Set the application to automatically start when the system boots. This can be done in the kiosk software admin panel.
  • Deactivate all keys that might be used for closing down the browser, adding windows etc. in the kiosk software. You should at least deactivate the keys F1 – F12, Ctrl left, Ctrl right and tab in the kiosk software. Be careful the deactivated key is not part of the master key combination!
  • In the browser Settings go to Options->Details and uncheck the boxes which might produce unwanted popups on the screen like offering content translations etc.
  • While the Web safe browser allows to block specific URLs and domains, when using a different one you have to use your own proxy server or browser plugin if you want to prevent users from surfing to unwanted URLs.

How to specify redirect url in Wordpress comments.php

By default the comments.php file can be used to display comments and a comments form for a post.

If you want to redirect to a specific page, after having submitted a comment you can do so as follows:

Simply insert a hidden field with name  “redirect_to“  in the comments form to tell Wordpress where to redirect users after submitting comments.


TaoGeoViz

Dieses Plugin ermöglicht die Integration von Google Maps in eine Wordpress Seite, sowohl im front-end Bereich einer Anwendung als auch im back-end Bereich. Im front-end dient das Plugin dazu gewünschte Punkte, sogenannte POIs (points of interest) auf einer Landkarte anzuzeigen. Die anzuzeigenden Orte können die Positionen von Wordpress-artikeln markieren oder andere interessante Punkte markieren (z.B. Filialen einer Geschäftekette). Das Aussehen der anzuzeigenden Punkte kann leicht angepasst werden.

Bei Klicken eines Punktes auf der Karte können eine Vorschau oder beliebige Informationen zu diesem Punkt eingeblendet werden. Durch das Zusammenfassen von Punkten in Ebenen, können Ebenen nach Belieben ein- und ausgeblendet werden. Über die Vergabe von eindeutigen IDs für gezeichnete Punkte ist es leicht möglich, die Kartenansicht mit einer Listenansicht nahtlos zu kombinieren. Neben der Anzeige von einfachen Punktobjekten ist es weiters möglich Linienzüge und geschlossene Flächen anzuzeigen.

Im back-end Bereich einer Anwendung kommt das Plugin vor allem zum Einsatz um Artikeln eine geographische Position zuzuordnen. Das setzen eines Punktes erfolgt entweder durch Ziehen und Fallenlassen eines Markers, oder durch Eingabe einer Adresse.