treckstar

WordPress MultiSite Custom BreadCrumbs NavXT Plugin

Jul 23rd, 2018
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. add_action('bcn_after_fill', 'post_landing_page_breadcrumb_adder');
  2. function post_landing_page_breadcrumb_adder($breadcrumb_trail)
  3. {
  4.     /**
  5.     * Get multi-site blog id..
  6.     */
  7.     $site_id = get_current_blog_id();
  8.  
  9.     /**
  10.     * Only execute if we are on a post..
  11.     */
  12.     if ( ! is_singular( [ 'post' ] ) ) {
  13.         return;
  14.     }
  15.  
  16.     /**
  17.     * Default breadcrumb template..
  18.     */
  19.     $breadcrumb_template = '<span class="breadcrumb-link-wrap" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem" property="itemListElement" typeof="ListItem"><a itemprop="item" property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
  20.  
  21.     /**
  22.     * Store the first and last breadcrumbs, we're rebuilding the middle part..
  23.     */
  24.     $breadcrumb_root = reset( $breadcrumb_trail->breadcrumbs );
  25.     $breadcrumb_end = end( $breadcrumb_trail->breadcrumbs );
  26.  
  27.     /**
  28.     * Begin building our custom breadcrumb, add in as many conditions as necessary..
  29.     */
  30.     $multisite_page = null;
  31.     $mutlisite_page_breadcrumb_title = null;
  32.     $custom_page = null;
  33.     $breadcrumb_title = null;
  34.  
  35.     if ( $site_id == 2 ) {
  36.         $multisite_page = get_page_by_path( '/about/' );
  37.         $mutlisite_page_breadcrumb_title = __( 'About' );
  38.  
  39.         $custom_page = get_page_by_path( '/about/news/' );
  40.         $breadcrumb_title = __( 'News' );
  41.     }
  42.     else if ( $site_id == 3 ) {
  43.         $multisite_page = get_page_by_path( '/admissions/' );
  44.         $mutlisite_page_breadcrumb_title = __( 'Admissions' );
  45.  
  46.         // WEIRD ITS GIVING ME THE WRONG URL...
  47.         //$custom_page = get_page_by_path( '/admissions/blue-hose/' );
  48.         $custom_page = get_page( 2152 );
  49.         $breadcrumb_title = __( 'Be A Blue Hose' );
  50.     }
  51.     else if ($site_id == 6 ) {
  52.         $multisite_page = get_page_by_path( '/giving/' );
  53.         $mutlisite_page_breadcrumb_title = __( 'Giving' );
  54.  
  55.         $custom_page = get_page_by_path( '/giving/stories/' );
  56.         $breadcrumb_title = __( 'Stories' );
  57.     }
  58.     else {
  59.         return;
  60.     }
  61.    
  62.     /**
  63.     * Create the breadcrumb object..
  64.     */
  65.     $mutlisite_page_breadcrumb_link = get_the_permalink( $multisite_page->ID );
  66.     $breadcrumb_link = get_the_permalink( $custom_page->ID );
  67.  
  68.     $multisite_breadcrumb = new bcn_breadcrumb( $mutlisite_page_breadcrumb_title, $breadcrumb_template, [], $mutlisite_page_breadcrumb_link, $multisite_page->ID );
  69.     $custom_item_breadcrumb = new bcn_breadcrumb( $breadcrumb_title, $breadcrumb_template, [], $breadcrumb_link, $custom_page->ID );
  70.  
  71.     /**
  72.     * Update the Breadcrumb NavXT object..
  73.     */
  74.     $breadcrumb_trail->breadcrumbs = [
  75.         $breadcrumb_root,
  76.         $custom_item_breadcrumb,
  77.         $multisite_breadcrumb,
  78.         $breadcrumb_end,
  79.     ];
  80. }
Advertisement
Add Comment
Please, Sign In to add comment