WordPress Menu Custom Walker Class

The easiest way is to extend the Walker_Nav_Menu class rather than the Walker_Class, (as the parent / ID fields are set and often you want to maintain some of the mark-up etc). The main methods are: start_el / end_el – responsible for displaying an element in a list start_lvl / end_lvl – responsible for displaying … Read more

Assign posts to taxonomy terms instead of the taxonomy terms to posts?

I think the “Featured Post Manager” plugin will be closer to what you’re looking for: http://wordpress.org/extend/plugins/featured-post-manager/screenshots/ The language used is somewhat confusing, and it may not work for custom taxonomies (directories) or custom types (people), BUT you can probably take the code and customize it to work for those classes of things instead, as well … Read more

How do I dynamically populate wp_nav_menu from a custom taxonomy?

I would go for custom nav menu walker… //define the custom post type and custom taxonomy define(“MENU_CPT”, “people”); define(“MENU_CT”, “club”); //custom function for selecting posts based on a term function get_posts_by_term($term_id, $post_type=MENU_CPT, $taxonomy=MENU_CT) { $args = array( ‘posts_per_page’ => -1, ‘post_type’ => $post_type, ‘tax_query’ => array( array( ‘taxonomy’ => $taxonomy, ‘field’ => ‘id’, ‘terms’ => … Read more

Display only page specific sub menu items using Custom Walker

Here is a much simpler implementation: class UL_Submenu_Walker extends Walker_Nav_Menu { private $hidden = false; function start_lvl(&$output, $depth) { if($depth == 0) { $style = $this->hidden ? “” : “display:none;”; } $output .= “<ul class=\”submenu-“.$depth.”\” style=””.$style.””>”; } function start_el(&$output, $item, $depth, $args) { $class_names = $value=””; $classes = empty( $item->classes ) ? array() : (array) … Read more

How does a minimal menu walker look like?

You could create a very simple walker, like this one. To detect the current item, inspect $item->current. It is TRUE for the current item only. I wouldn’t add a class, but deactivate the useless link completely, because it doesn’t have to be clickable anyway. Example: class One_Line_Walker extends Walker { public function walk( $elements, $max_depth … Read more

Custom menu walker: how can i check first item

Count the level 0 elements in a static variable in the method and add an extra class if you hit the third. Sample code: function start_lvl(&$output, $depth) { static $column = 1; $indent = str_repeat(“\t”, $depth); if ($depth > 0) { $output .= “\n$indent<ul class=”subsubmenu”>\n”; } else { $column += 1; $extra = 3 === … Read more

Comment Walker vs. Comment Callback

We could rewrite: wp_list_comments( array( ‘callback’ => ‘bootstrap_comment_callback’, )); with the null walker parameter: wp_list_comments( array( ‘walker’ => null, ‘callback’ => ‘bootstrap_comment_callback’, )); which means we are using the default Walker_Comment class: wp_list_comments( array( ‘walker’ => new Walker_Comment, ‘callback’ => ‘bootstrap_comment_callback’, )); The Walker_Comment::start_el() method is just a wrapper for one of these protected methods: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)