Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If page is empty than it works like a trigger to open sublevel pages with content
#4
I had a simmilar need, so I came up with this. It uses i18n plugin's navigation API functions.
PHP Code:
function custom_tree_nav$current_slug null$entries false )
{
    
$current_slug $current_slug $current_slug get_page_slugfalse );

    if( !
$entries )
        
$entries return_i18n_menu_data$current_slug099I18N_SHOW_MENU );

    echo 
'<ul>';
    foreach( 
$entries as $entry )
    {
        
# 'current' menu entry class tag.
        
$current $entry['current'] ? ' current' '';

        
# Get menu name, or page name if menu name empty.
        
$menu $entry['menu'] ? $entry['menu'] : $entry['title'];

        
# This may need to be adjusted according to installation specifics
        
$slug '/'.$entry['url'];

        
$url $entry['url'];

        if( !empty( 
$entry['children'] ) )
        {
            
# Might want to throw an 'a' instead of 'span'.
            
echo '<li><span class="'.$url.$current.'">'.$menu.'</span>';
            
custom_tree_nav$current_slug$entry['children'] );
            echo 
'</li>'."\n";
        }
        
        else
            echo 
'<li><a class="'.$url.$current.'" href="'.$slug.'" target="_self">'.$menu.'</a></li>'."\n";
    }
    echo 
'</ul>'."\n";


Put this function in your theme's functions.php file, then call it from your template file like this: <?php custom_tree_nav(); ?>

It will create the raw HTML menu code. Be aware that no checks are made whether a page is empty or not, rather a page is checked for existence of children. Also, no attempt was made to recreate the url structure, as GS will (with proper configuration) accept anything after the last slash as a page slug, and return the correct page.

Any CSS styling + JS behavior is up to you.
Reply


Messages In This Thread
RE: If page is empty than it works like a trigger to open sublevel pages with content - by Everyone - 2014-02-17, 08:08:03



Users browsing this thread: 1 Guest(s)