• atlaswu

    (@atlaswu)


    I want to insert a page between the breadcrumbs for articles in a specified category. I can put the last program in this discussion directly into function.php and it will run successfully as expected in front. However, when entering the Widgets in the Appearance, the Fatal error: Uncaught Error: Call to a member function get_id() will appear.

    add_filter('bcn_after_fill', 'my_static_breadcrumb_adder');
    function my_static_breadcrumb_adder($breadcrumb_trail) {
    	if($breadcrumb_trail->breadcrumbs[count($breadcrumb_trail->breadcrumbs)-2]->get_id() === 1000){
    		$new_breadcrumb = new bcn_breadcrumb('AAAAA', NULL, array('post'), '/page_url/', NULL, true);
    		array_splice($breadcrumb_trail->breadcrumbs, -1, 0, array($new_breadcrumb));
    	}
    }
    • This topic was modified 1 year ago by atlaswu.
Viewing 1 replies (of 1 total)
  • Plugin Author John Havlik

    (@mtekk)

    The code probably tries to access something that doesn’t exist. That is, your breadcrumbs array may not have any members, or only a single member (which would result in the -2 in the calculation for the key try to access something that doesn’t exist). You probably should check that there are more than 2 members in the breadcrumbs array before running that bit of code.

    Also note, bcn_after_fill is an action not a filter so the hook registration isn’t correct there (it’ll work but isn’t technically correct).

Viewing 1 replies (of 1 total)
  • The topic ‘Insert item between breadcrumb on specific category of posts’ is closed to new replies.