Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Register Navigation */
- function register_my_menus() {
- register_nav_menus(
- array(
- 'cat_nav' => __( 'Katzen-Navigation'),
- )
- );
- }
- add_action ('init', 'register_my_menus');
- /* Widget: Dein eigenes Widget */
- class Toni_Menu_Widget extends WP_Widget {
- function Toni_Menu_Widget() {
- $widget_ops = array('classname' => 'widget_wp_own_nav', 'description' => 'Dieses Widget zeigt die tolle Katzen-Navigation an..' );
- $this->WP_Widget('wp_own_nav', 'Rassekatzen » Katzen Menรผ', $widget_ops);
- }
- function widget($args, $instance) {
- extract($args, EXTR_SKIP);
- global $post;
- echo $before_widget;
- if($instance['title']) {?><p class="h1"><?php echo $instance['title'] ?></p><?php }
- wp_nav_menu(
- array(
- 'menu' => 'cat_navigtion', /* menu name */
- 'menu_class' => 'blognavigation',
- 'theme_location' => 'cat_nav', /* where in the theme it's assigned */
- 'container' => 'false', /* container class */
- 'depth' => '1', /* suppress lower levels for now */
- 'walker' => new description_walker()
- )
- );
- echo $after_widget;
- }
- function update($new_instance, $old_instance) {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- return $instance;
- }
- function form($instance) {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
- $title = $instance['title'];
- }
- }
- register_widget('Toni_Menu_Widget');
- /* Walker */
- 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 ) . '"';
- if(apply_filters( 'the_title', $item->title, $item->ID ) != "divider") {
- $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 ) .'"' : '';
- $item_output = $args->before;
- $item_output .= '<a'. $attributes .'>';
- /* Hier das ACF Field einbauen */
- if(get_field('name_des_fields', 'category_'.$item->ID') {
- $item_output .= get_field('name_des_fields', 'category_'.$item->ID');
- }
- $item_output .= $args->link_before .apply_filters( 'the_title', $item->title, $item->ID );
- $item_output .= $args->link_after;
- $item_output .= '</a>';
- $item_output .= $args->after;
- $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
- }
- function start_lvl(&$output, $depth) {
- $indent = str_repeat("\t", $depth);
- $output .= "\n$indent<ul>\n";
- }
- function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
- $id_field = $this->db_fields['id'];
- if ( is_object( $args[0] ) ) {
- $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
- }
- return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement