eric
04-21-2011, 10:01 AM
With WordPress you can set Descriptions (or Sub-Text) for your individual navbar pages when using the Custom Menus. To do this, however, you need to add a bit of code and tweak a few settings which is what this tutorial is all about.
The end result should look something like this:
http://catalysttheme.com/img/forum/navbar-descriptions.png (http://catalysttheme.com/img/forum/navbar-descriptions.png)
The Video Tutorial that walks you through the process is here:
http://catalysttheme.com/how-to-add-navbar-page-descriptions-in-catalyst/
Here is the Custom Functions code (you can paste this in your /wp-content/themes/dynamik/custom-functions.php file):
/* Build the description_walker class and integrate it into the Nav Menu */
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
function my_wp_nav_menu_args( $args = '' )
{
$args['walker'] = new description_walker();
return $args;
}
class description_walker extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth, $args )
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend_tag = '<span class="m-title">';
$append_tag = '</span>';
$description = ! empty( $item->description ) ? '<span class="m-desc">'.esc_attr( $item->description ).'</span>' : '';
if( $depth != 0 )
{
$description = $append_tag = $prepend_tag = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend_tag.apply_filters( 'the_title', $item->title, $item->ID ).$append_tag;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
And here is the Custom CSS code (you can paste this in your Advanced Options > Custom CSS):
#navbar-1-wrap {
height: 50px;
}
#nav-1 li a .m-title {
margin: 0;
padding: 0;
font-weight: bold;
line-height: 15px;
display: block;
}
#nav-1 li a .m-desc {
margin: 0;
padding: 0;
color: #AAAAAA;
font-size: 12px;
font-weight: normal;
line-height: 15px;
display: block;
}
********************
UPDATE: The following PHP and CSS code should provide the same functionality, but with less code and a slight improvement of overal functionality:
The end result should look something like this:
http://catalysttheme.com/img/forum/catalyst-navbar-descriptions.png (http://catalysttheme.com/img/forum/catalyst-navbar-descriptions.png)
Here is the Custom Functions code (you can paste this in your /wp-content/themes/dynamik/custom-functions.php file):
add_filter( 'walker_nav_menu_start_el', 'custom_add_menu_description', 10, 4 );
function custom_add_menu_description( $item_output, $item, $depth, $args )
{
$args = (array) $args;
if ( $args['theme_location'] == 'primary' ) {
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . "<span class=\"menu-description\">{$item->post_content}</span><", $item_output );
}
else {
return $item_output;
}
}
And here is the Custom CSS code (you can paste this in your Advanced Options > Custom CSS):
#navbar-1-wrap {
height: 50px;
}
.menu-description {
color: #777;
font-size: 12px;
font-style: italic;
display: block;
clear: both;
}
********************
Enjoy! :)
Eric
The end result should look something like this:
http://catalysttheme.com/img/forum/navbar-descriptions.png (http://catalysttheme.com/img/forum/navbar-descriptions.png)
The Video Tutorial that walks you through the process is here:
http://catalysttheme.com/how-to-add-navbar-page-descriptions-in-catalyst/
Here is the Custom Functions code (you can paste this in your /wp-content/themes/dynamik/custom-functions.php file):
/* Build the description_walker class and integrate it into the Nav Menu */
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
function my_wp_nav_menu_args( $args = '' )
{
$args['walker'] = new description_walker();
return $args;
}
class description_walker extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth, $args )
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend_tag = '<span class="m-title">';
$append_tag = '</span>';
$description = ! empty( $item->description ) ? '<span class="m-desc">'.esc_attr( $item->description ).'</span>' : '';
if( $depth != 0 )
{
$description = $append_tag = $prepend_tag = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend_tag.apply_filters( 'the_title', $item->title, $item->ID ).$append_tag;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
And here is the Custom CSS code (you can paste this in your Advanced Options > Custom CSS):
#navbar-1-wrap {
height: 50px;
}
#nav-1 li a .m-title {
margin: 0;
padding: 0;
font-weight: bold;
line-height: 15px;
display: block;
}
#nav-1 li a .m-desc {
margin: 0;
padding: 0;
color: #AAAAAA;
font-size: 12px;
font-weight: normal;
line-height: 15px;
display: block;
}
********************
UPDATE: The following PHP and CSS code should provide the same functionality, but with less code and a slight improvement of overal functionality:
The end result should look something like this:
http://catalysttheme.com/img/forum/catalyst-navbar-descriptions.png (http://catalysttheme.com/img/forum/catalyst-navbar-descriptions.png)
Here is the Custom Functions code (you can paste this in your /wp-content/themes/dynamik/custom-functions.php file):
add_filter( 'walker_nav_menu_start_el', 'custom_add_menu_description', 10, 4 );
function custom_add_menu_description( $item_output, $item, $depth, $args )
{
$args = (array) $args;
if ( $args['theme_location'] == 'primary' ) {
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . "<span class=\"menu-description\">{$item->post_content}</span><", $item_output );
}
else {
return $item_output;
}
}
And here is the Custom CSS code (you can paste this in your Advanced Options > Custom CSS):
#navbar-1-wrap {
height: 50px;
}
.menu-description {
color: #777;
font-size: 12px;
font-style: italic;
display: block;
clear: both;
}
********************
Enjoy! :)
Eric