Filter Menus in Thematic

There’s a few ways to alter the Thematic menu through hooks and filters. Here’s a list of options.

Use wp_list_pages

By using wp_list_pages, you can change the order of the menu, exclude certain items, or just pick the ones you want to display. Add this code to your child theme’s functions.php to start:

1
2
3
4
5
6
7
8
9
10
11
//  Add a dynamic menu using wp_list_pages
 
function childtheme_menu() { ?>
     <div class="menu">
          <ul class="sf-menu">
                <?php wp_list_pages('title_li='); ?>
          </ul>
     </div>
<?php }
 
add_action('wp_page_menu','childtheme_menu');

Use wp_page_menu with Arguments

Here’s the same code from above, but with arguments to exclude pages 4 & 7 from the menu and sort by post date. A full list of all the arguments can be found in the codex.

1
2
3
4
5
6
7
8
9
10
11
//  Add a dynamic menu using wp_list_pages
 
function childtheme_menu() { ?>
     <div class="menu">
          <ul class="sf-menu">
                <?php wp_list_pages('exclude=4,7&sort_column=post_date&title_li='); ?>
          </ul>
     </div>
<?php }
 
add_action('wp_page_menu','childtheme_menu');

Hardcode the Menu

The simplest way to get the links you want might be to replace the menu with hardcoded html. This way you can name the links whatever you want, and point them to any url. Make sure to put this code in your child theme’s functions.php.

1
2
3
4
5
6
7
8
9
10
11
12
//  Add a hardcoded menu
 
function childtheme_menu() { ?>
     <div class="menu">
          <ul class="sf-menu">
                <li><a href="http://mysite.com/link-one">My Link One</li>
                <li><a href="http://mysite.com/link-two">My Link Two</li>
          </ul>
     </div>
<?php }
 
add_action('wp_page_menu','childtheme_menu');

Filter wp_list_pages

If you want to dig even deeper into the function, you could filter the wp_list_pages argument itself. I haven’t experimented extensively with this- so I’m not sure if it would effect your widgets or plug-ins. But have a go and let me know if it works. The following filter would tack a categories drop down menu to the end of page.

1
2
3
4
5
6
7
8
9
// Add a drop down menu for categories
 
function add_childtheme_category_menu($args) {
	$categories = wp_list_categories('echo=0&title_li=<li><a href="#">Categories</a>');
	$args .= $categories . '</li>';
	return $args;
	}
 
add_filter('wp_list_pages','add_childtheme_category_menu');

Useful Links

This entry was posted in Thematic. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Jess
    Posted December 4, 2009 at 10:24 am | Permalink

    Can this be used in the same way for wp_list_categories?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting