taenzer.me blog

Random stuff from Poppelsdorf 
Filed under

wordpress

 

Fast and simple 3-level-navigation for Wordpress: show top level, parent and subpages only when on a subpage

Every now and then, we're using Wordpress as a CMS for clients' sites that require only basic content and navigation. 

What bugs me every time is the navigation. For me, a reasonable navigation is able to show up to 3 sublevels, and when a menu item is clicked, it lists all of its subpages, and when a subpage is clicked, it lists its subpages and so on.

What's important here is to have the parent and ancestor pages (or top level pages) stay where they are when you dig deeper. Even if there is a breadcrumb available, most users tend to use the main navigation to return to the previous level. Plus, this sort of step-by-step navigation gives the user a reasonable overview of his or her possible options. 

Navigation ( active links are bold):

a)

  • Home
  •   -Subpage 1
  •   -Subpage 2
  •   -Subpage 3

b)

Subpage 1 

  • Subpage 1
  •   -Subpage 1.1
  •   -Subpage 1.2
  • -Subpage 2 (this site has children too, but they only show when the item is clicked)
  • -Subpage 3

c)

Subpage 1 

  • Subpage 1
  •   -Subpage 1.1
  •   -Subpage 1.2
  • -Subpage 2
  • -Subpage 3

There are many ways to create that sort of navigation, but they all have in common that you need to have a certain level of PHP knowledge. 

The basic code snippet to get a list of pages is <?php wp_list_pages(); ?> with its arguments. You can combine it with a walker function if you need more specific functions. 

I have to admit I prefer writing my own function than using any kind of plugin to do it for me. But this time I'm giving in. 

The Simple Section Navigation Plugin does exactly what we need, and nothing else. It's slim and it works. You can use it as a widget in your sidebar, but you can as well call it from inside of your template file. 

Bildschirmfoto_2011-05-16_um_16

It also puts the title of the top level page above the navigation. If you don't want that, go into the plugin's php-file and on line 96 simply change

echo $before_widget.$before_title.$sect_title.$after_title."<ul>"; 

to

echo $before_widget."<ul>";

By this you only prevent the output of this part of the widget. (h3 and section title)

Other useful code snippets:

1) Echo the title of the top level page (in a 3-level-navigation level 0)

global $post; $post_ancestors = get_post_ancestors($post); $top_page = $post_ancestors ? end($post_ancestors) : $post->ID; $toptitle = get_the_title($top_page); echo $toptitle;

2) Echo the title of the parent page (in a 3-level-navigation level 1 or 2, depending on which subpage you're on)

$parent_title = get_the_title($post->post_parent); echo $parent_title;

(Plugin Version 2.1., Wordpress 3.1.2)

Filed under  //   3-level-navigation    navigation   only   show children   show parent pages when on subpage   show subpages   show subsites   show title of parent page   show title of top level page   template   widget   wordpress  

Firefox-bug: Close button of Lightbox2-Plugin with Wordpress not working, producing a scrollbar and blue outline instead of closing

We're using Wordpress and NextGenGallery plugin for a client's site, with the possibility to open images with lightbox in full screen size. We're using Stimuli's Lightbox 2-plugin for this. It's working fine in Safari.

But in Firefox and Internet Explorer, somehow all images get a blue outline, and the close-button (which is an image) underneath the opened lightbox-image gets one. Clicking the close button would also produce a scrollbar, and only second click would close the image. I believed this to be a line-height or height problem, and in fact it is. Firefox and IE add this 1px blue outline to links as such and links or images in focus. So putting only the border to 0px won't work.

Scrollbar

Instead, my fix is this:

a, a img, a:focus, a img:focus{
    border: 0px;
    outline: none;
}   

Afterwards, the close button won't show this odd behaviour anymore and clicking the "X" will close the image.

In addition, if you happen to experience the close button not working at all, adding

#stimuli_imageData a#stimuli_bottomNavClose {

    position: relative;   
    z-index: 1000;

}

will do the trick. There is some overlaying issue causing this.

 

 

Filed under  //   blue border   close button   firefox   lightbox   lightbox 2   nextgenGallery   not working   outline   scrollbar   second click   stimuli   wordpress