Custom Nav Walker sub-menu HTML construct

Solution: Copy paste the below code into your function. and then in template use my_nav_menu($menu_location); //put this in your functions class MY_Menu_Walker_Ext extends Walker { var $tree_type = array(‘post_type’, ‘taxonomy’, ‘custom’); var $db_fields = array(‘parent’ => ‘menu_item_parent’, ‘id’ => ‘db_id’); function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { $output .=”<li><h2 … Read more

Extend walker – navigation, adding data attribute to a tag

This is how I added data attribute to my menu It simply adds data-title=”menu-title” to each link on my main nav, change it to adapt to your need. You don’t actually need to use Nav Walker to add this add_filter( ‘nav_menu_link_attributes’, ‘cfw_add_data_atts_to_nav’, 10, 4 ); function cfw_add_data_atts_to_nav( $atts, $item, $args ) { $atts[‘data-title’] = $item->post_title; … Read more

Assign different category colours to different categories in the main menu

Got it to work, finally! Nothing like a good sleep to restart your brain 🙂 Updated code that works: $item_output = $args->before; if( $item->object == ‘category’ ) { $category = get_category( $item->object_id ); $category_color = get_field( ‘category_color’, $category); $item_output .= ‘<a style=”color:’ . $category_color . ‘;”‘. $attributes .’>’; } else { $item_output .= ‘<a’. $attributes … Read more

Single.php Active Category Class

As vancoder notes, a post can have multiple categories and the following code highlights each category, as well as the current month for the post. Add to your theme’s functions.php. // Generate active class for categories when viewing single posts // Props to Sam Nabi http://samnabi.com/blog/highlight-the-current-category-for-single-posts-in-wordpress function singlePostActiveCat ($CatText) { global $post; if (is_singular()) { … Read more

Bar separated navigation by extending Walker_Page

This is what I went with in the end. Although it only will work correctly if you are using a depth of one: class Bar_List_Walker_Page extends Walker_Page { public $count; public $running_count; function __construct() { $this->count = 0; $this->running_count = 0; } function start_el(&$output, $page, $depth, $args, $current_page) { global $post; extract($args, EXTR_SKIP); $css_class = … Read more

Customize comment list markup

You should use wp_list_comments(), because this will call a Walker class that can handle comment threads: // from wp_list_comments() if ( empty($walker) ) $walker = new Walker_Comment; $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); Walker_Comment handles the markup for the comments. You can pass a custom walker to change it. Example: class Simple_Comment_Walker extends Walker_Comment { function … Read more

Adding ul class with wp_list_categories Custom Walker

You should be extending Walker_Category not the main Walker class. class Walker_Simple_Example extends Walker_Category { function start_lvl(&$output, $depth=1, $args=array()) { $output .= “\n<ul class=\”product_cats\”>\n”; } function end_lvl(&$output, $depth=0, $args=array()) { $output .= “</ul>\n”; } function start_el(&$output, $item, $depth=0, $args=array()) { $output .= “<li class=\”item\”>”.esc_attr( $item->name ); } function end_el(&$output, $item, $depth=0, $args=array()) { $output .= … Read more

Bar separated navigation by extending Walker_Nav_Menu

You can use the menu order inside the item to see if it’s not first. If it isn’t have it draw the character before the anchor. class Bar_List_Walker_Nav_Menu extends Walker_Nav_Menu { private $separator = ” | “; function start_el(&$output, $item, $depth, $args) { if($item->menu_order > 1){ $output .= $this->separator; } $attributes = ! empty( $item->target … Read more

Customizing Walker_Nav_Menu

You just need to create your own walker class and extend start_el method. This method builds a link and you will be able to add your span before it: class Wpse8170_Menu_Walker extends Walker_Nav_Menu { var $number = 1; function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $indent = … Read more

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