• How do I manually put the blog link back into the breadcrumb trail when I’m using a non-static blog page? Meaning that under my Reading settings, I don’t have a blog page selected.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter m7csat

    (@m7csat)

    Here’s my complete hack job of a solution that basically switches the last two elements:

    add_action('bcn_after_fill', 'my_static_breadcrumb_adder');
    function my_static_breadcrumb_adder($trail)
    {
    if ( is_single() ) {
        $trail->add(new bcn_breadcrumb('Blog', NULL, array('blog'), '/blog'));
        $bccount = count($trail->breadcrumbs);
        $tempspot = $trail->breadcrumbs[$bccount - 2]; 
        $trail->breadcrumbs[$bccount - 2] = $trail->breadcrumbs[$bccount - 1];
        $trail->breadcrumbs[$bccount - 1] = $tempspot;
    }
    }

    If anyone has a better idea, I’m open to it.

    Plugin Author John Havlik

    (@mtekk)

    Just a few notes on this. Rather than calling bcn_breadcrumb_trail::add(), normally I would manually instantiate a new bcn_breadcrumb object. Then inject it into the correct spot into bcn_breadcrumb_trail::breadcrumbs using the PHP array_splice() function. That saves you from having to juggle around entities in the bcn_breadcrumb_trail::breadcrumbs array.

    Thread Starter m7csat

    (@m7csat)

    Thanks, John. Would you mind posting sample code? I tried array_splice based on something I found on Stack Overflow and it kept throwing errors.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Blog link for non-static blog page’ is closed to new replies.