Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #520603

    Hello, I need to change some behaviour of function avia_breadcrumbs(), that is placed in class-breadcrumb.php. I want to modify it in the child-theme, not in parent. But this function is not envolved in a if(!function_exists(‘avia_breadcrumbs’){} that would be necessary in order to hook the funciton in child theme.

    As I don’t want to modify core fields, I can rewrite a new function (copied and modified the original function) in the child functions.php, but I can’t find how/where to change de theme to order it to use this new function instead the original, also in the child theme, not in parent one.

    Could you help me?

    Thanks in advance.

    #520660

    Hey nuriarai3!

    The class is wrapped with a “class_exists” function so you can copy lines 3 – 144 to your child theme functions.php file and it will be used instead.

    Regards,
    Elliott

    #520669

    Hei Elliott, thanks for your quicly response.

    I think I didn’t explain well, in the class-breadcrumb.php there are one class: avia_breadcrumb() that is from line 1 to 144 and is wrapped with “class_exists”. This is correct. But I’m talking about a function written in the same file, but from line 149, that begin with this comments:
    /*———————————————————————————–*/
    /* avia_breadcrumbs() – Custom breadcrumb generator function */
    /*
    /* Params:
    /*
    /* Arguments Array:
    /*
    /* ‘separator’ – The character to display between the breadcrumbs.
    /* ‘before’ – HTML to display before the breadcrumbs.
    /* ‘after’ – HTML to display after the breadcrumbs.
    /* ‘front_page’ – Include the front page at the beginning of the breadcrumbs.
    /* ‘show_home’ – If $show_home is set and we’re not on the front page of the site, link to the home page.
    /* ‘echo’ – Specify whether or not to echo the breadcrumbs. Alternative is “return”.
    /* ‘show_posts_page’ – If a static front page is set and there is a posts page, toggle whether or not to display that page’s tree.
    /*
    /*———————————————————————————–*/

    This function is called avia_breadcrumbs() (with an “s” at the end to distinct from class avia_breadcrumb(). As I can see, this function is not wrapped by an “class_exists” statement, so it can’t be cloned in child theme functions.php. And this function seems to be indepent to the class, cause it’s not called inside the class.
    I don’t know where in the theme (may be there is an option in option panel, but I can’t see it) is calling this function instead de class. This is not a project of mine, but a colleague are asked me to help with a modification in the breadcrum. And actually the theme in this install is using this function and not the class. You can see it in action in http://pando.topimatge.com/horno-39-microondas-22-l-phm-9500/
    I have made the change in the function (not class) (but in parent theme) and is running correctly. But I would have to can do it in the theme child, not parent.

    Any idea? Thanks in advance

    Núria

    #521124

    Hi!

    What are you trying to change exactly? On line 203 you can see there is a filter that you can use.

    $args = apply_filters( 'avia_breadcrumbs_args', $args );
    

    An example in your child theme would look like this.

    add_filter( 'avia_breadcrumbs_arg', 'enfold_customization_breadcrumbs', 10, 1 );
    function enfold_customization_breadcrumbs( $args ) {
        $args['echo'] = true;
        return $args;
    }

    Cheers!
    Elliott

    • This reply was modified 9 years, 1 month ago by Elliott.
    #521202

    Hi Elliot, thanks for your answer, but the apply_filters() is only for the function args, and I don’t need to modify the args, they are ok.
    What I need is hack the breadcrumb when it is a child of certain categories (hornos/placas) to put an specified page as parent instead of the archive page of the category. This is because they are using posts like products or portfolio, and this posts has a page (normal page) as a parent.
    So I have done this change begining in line 301:

     if(isset($category[0]) && empty($parents))
                    {
                        // nra: modified to show the page instead the category
                        //category hornos = 8, category plaques = 8, page hornos = 106 , page placas = 109
                        $catid = $category[0]->term_id;
                        if( $catid == 8 or $catid == 9) {
                            if($catid == 8 ) {
                                $trail[] = '<a  href="'.get_page_link(106).'">'.get_the_title(106).'</a>';
                            } elseif($catid == 9) {
                                $trail[] = '<a  href="'.get_page_link(108).'">'.get_the_title(108).'</a>';
                            }
                        }else {
                            $trail[] = '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
                        }
                        //end nra
                    }

    May be there is another approach that I have not thought, or not.

    Thanks in advance!

    Núria

    #521444

    Hi!

    Use the avia_breadcrumbs_trail filter inside the functions.php file. Example:

    add_filter( 'avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 2 );
    function avia_breadcrumbs_trail_mod( $trail, $args ) {
    	$id = avia_get_the_ID();
    	$category = get_the_category($id);
    	if(isset($category) && is_singular('post')) {
            // nra: modified to show the page instead the category
            //category hornos = 8, category plaques = 8, page hornos = 106 , page placas = 109
            $catid = $category[0]->term_id;
            if( $catid == 8 or $catid == 9) {
                if($catid == 8) {
                    $trail[1] = '<a  href="'.get_page_link(106).'">'.get_the_title(106).'</a>';
                } elseif($catid == 9) {
                    $trail[1] = '<a  href="'.get_page_link(108).'">'.get_the_title(108).'</a>';
                }
            } else {
                $trail[1] = '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
            }
        }
    	return $trail;
    }

    Best regards,
    Ismael

    #521451

    Thank you very much, ismael. It was my fault! I didn’t noticed the apply filters for trail:

    /* Allow child themes/plugins to filter the trail array. */
    	$trail = apply_filters( 'avia_breadcrumbs_trail', $trail, $args );

    I will use it.

    Thanks!

    Núria

    #521546

    Hi,

    Great, please let us know if you should have any more problems on the topic.

    Regards,
    Rikard

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.