Advertisement
catchmahesh

catch_responsive breadcrumb.php

Jun 24th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.72 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The template for displaying the Breadcrumb
  4.  *
  5.  * @package Catch Themes
  6.  * @subpackage Catch Responsive Pro
  7.  * @since Catch Responsive 1.0
  8.  */
  9.  
  10. if ( ! defined( 'CATCHRESPONSIVE_THEME_VERSION' ) ) {
  11.     header( 'Status: 403 Forbidden' );
  12.     header( 'HTTP/1.1 403 Forbidden' );
  13.     exit();
  14. }
  15.  
  16. /**
  17.  * Add breadcrumb.
  18.  *
  19.  * @action catchresponsive_after_header
  20.  *
  21.  * @since Catch Responsive 1.0
  22.  */
  23. if( !function_exists( 'catchresponsive_add_breadcrumb' ) ) :
  24.  
  25.     function catchresponsive_add_breadcrumb() {
  26.         $options    = catchresponsive_get_theme_options(); // Get options
  27.  
  28.         if( isset ( $options['breadcumb_option'] ) && $options['breadcumb_option'] ) {
  29.             $showOnHome = ( isset ( $options['breadcumb_onhomepage'] ) && $options['breadcumb_onhomepage'] ) ? '1' : '0';
  30.  
  31.             $delimiter = '<span class="sep">'. $options['breadcumb_seperator'] .'</span><!-- .sep -->'; // delimiter between crumbs
  32.  
  33.             echo catchresponsive_custom_breadcrumbs( $showOnHome, $delimiter );
  34.         }
  35.         else
  36.             return false;
  37.     }
  38.  
  39. endif;
  40. add_action( 'catchresponsive_after_header', 'catchresponsive_add_breadcrumb', 50 );
  41.  
  42.  
  43. /**
  44.  * Breadcrumb Lists
  45.  * Allows visitors to quickly navigate back to a previous section or the root page.
  46.  *
  47.  * Adopted from Dimox
  48.  *
  49.  * @since Catch Responsive 1.0
  50.  */
  51. if( !function_exists( 'catchresponsive_custom_breadcrumbs' ) ) :
  52.  
  53.     function catchresponsive_custom_breadcrumbs( $showOnHome, $delimiter ) {
  54.  
  55.         /* === OPTIONS === */
  56.         $text['home']     = __( 'Home', 'catch-responsive' ); // text for the 'Home' link
  57.         $text['category'] = __( '%1$s Archive for %2$s', 'catch-responsive' ); // text for a category page
  58.         $text['search']   = __( '%1$s Search results for: %2$s', 'catch-responsive' ); // text for a search results page
  59.         $text['tag']      = __( '%1$s Posts tagged %2$s', 'catch-responsive' ); // text for a tag page
  60.         $text['author']   = __( '%1$s View all posts by %2$s', 'catch-responsive' ); // text for an author page
  61.         $text['404']      = __( 'Error 404', 'catch-responsive' ); // text for the 404 page
  62.  
  63.         $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
  64.         $before      = '<span class="breadcrumb-current">'; // tag before the current crumb
  65.         $after       = '</span>'; // tag after the current crumb
  66.         /* === END OF OPTIONS === */
  67.  
  68.         global $post, $paged, $page;
  69.         $homeLink   = home_url( '/' );
  70.         $linkBefore = '<span class="breadcrumb" typeof="v:Breadcrumb">';
  71.         $linkAfter  = '</span>';
  72.         $linkAttr   = ' rel="v:url" property="v:title"';
  73.         $link       = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s ' . $delimiter . '</a>' . $linkAfter;
  74.  
  75.  
  76.         if( is_front_page() ) {
  77.  
  78.             if( $showOnHome ) {
  79.                 echo '<div id="breadcrumb-list">
  80.                     <div class="wrapper">';
  81.  
  82.                     echo $linkBefore . '<a href="' . esc_url( $homeLink ) . '" ' . $linkAttr . '>' . $text['home'] . '</a>' . $linkAfter;
  83.  
  84.                     echo '</div><!-- .wrapper -->
  85.                 </div><!-- #breadcrumb-list -->';
  86.             }
  87.  
  88.         }
  89.         else {
  90.             echo '<div id="breadcrumb-list">
  91.                     <div class="wrapper">';
  92.  
  93.             echo sprintf( $link, $homeLink, $text['home'] );
  94.  
  95.             if( is_home() ) {
  96.                 if( $showCurrent == 1 ) {
  97.                     echo $before . get_the_title( get_option( 'page_for_posts', true ) ) . $after;
  98.                 }
  99.  
  100.             }
  101.             elseif( is_category() ) {
  102.                 $thisCat = get_category( get_query_var( 'cat' ), false );
  103.                 if( $thisCat->parent != 0 ) {
  104.                     $cats = get_category_parents( $thisCat->parent, true, false );
  105.                     $cats = str_replace( '<a', $linkBefore . '<a' . $linkAttr, $cats );
  106.                     $cats = str_replace( '</a>', $delimiter .'</a>' . $linkAfter, $cats );
  107.                     echo $cats;
  108.                 }
  109.                 echo $before . sprintf( $text['category'], '<span class="archive-text">', '&nbsp</span>' . single_cat_title( '', false ) ) . $after;
  110.  
  111.             }
  112.             elseif( is_search() ) {
  113.                 echo $before . sprintf( $text['search'], '<span class="search-text">', '&nbsp</span>' . get_search_query() ) . $after;
  114.  
  115.             }
  116.             elseif( is_day() ) {
  117.                 echo sprintf( $link, get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) ) ;
  118.                 echo sprintf( $link, get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ), get_the_time( 'F' ) );
  119.                 echo $before . get_the_time( 'd' ) . $after;
  120.  
  121.             }
  122.             elseif( is_month() ) {
  123.                 echo sprintf( $link, get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) ) ;
  124.                 echo $before . get_the_time( 'F' ) . $after;
  125.  
  126.             }
  127.             elseif( is_year() ) {
  128.                 echo $before . get_the_time( 'Y' ) . $after;
  129.  
  130.             }
  131.             elseif( is_single() && !is_attachment() ) {
  132.                 if( get_post_type() != 'post' ) {
  133.                     $post_type = get_post_type_object( get_post_type() );
  134.                     $slug      = $post_type->rewrite;
  135.                     printf( $link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name );
  136.                     if( $showCurrent == 1 ) {
  137.                         echo $before . get_the_title() . $after;
  138.                     }
  139.                 }
  140.                 else {
  141.                     $cat  = get_the_category();
  142.                     $cat  = $cat[0];
  143.                     $cats = get_category_parents( $cat, true, ''     );
  144.                     if( $showCurrent == 0 ) {
  145.                         $cats = preg_replace( "#^(.+)$#", "$1", $cats );
  146.                     }
  147.                     $cats = str_replace( '<a', $linkBefore . '<a' . $linkAttr, $cats );
  148.                     $cats = str_replace( '</a>', $delimiter .'</a>' . $linkAfter, $cats );
  149.                     echo $cats;
  150.                     if( $showCurrent == 1 ) {
  151.                         echo $before . get_the_title() . $after;
  152.                     }
  153.                 }
  154.             }
  155.             elseif( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  156.                 $post_type = get_post_type_object( get_post_type() );
  157.                 echo $before . $post_type->labels->singular_name . $after;
  158.             }
  159.             elseif( is_attachment() ) {
  160.                 $parent = get_post( $post->post_parent );
  161.                 $cat    = get_the_category( $parent->ID );
  162.  
  163.                 if( isset( $cat[0] ) ) {
  164.                     $cat = $cat[0];
  165.                 }
  166.  
  167.                 if( $cat ) {
  168.                     $cats = get_category_parents( $cat, true );
  169.                     $cats = str_replace( '<a', $linkBefore . '<a' . $linkAttr, $cats );
  170.                     $cats = str_replace( '</a>', $delimiter .'</a>' . $linkAfter, $cats );
  171.                     echo $cats;
  172.                 }
  173.  
  174.                 printf( $link, get_permalink( $parent ), $parent->post_title );
  175.                 if( $showCurrent == 1 ) {
  176.                     echo $before . get_the_title() . $after;
  177.                 }
  178.  
  179.             }
  180.             elseif( is_page() && !$post->post_parent ) {
  181.                 if( $showCurrent == 1 ) {
  182.                     echo $before . get_the_title() . $after;
  183.                 }
  184.  
  185.             }
  186.             elseif( is_page() && $post->post_parent ) {
  187.                 $parent_id   = $post->post_parent;
  188.                 $breadcrumbs = array();
  189.                 while( $parent_id ) {
  190.                     $page_child    = get_post( $parent_id );
  191.                     $breadcrumbs[] = sprintf( $link, get_permalink( $page_child->ID ), get_the_title( $page_child->ID ) );
  192.                     $parent_id     = $page_child->post_parent;
  193.                 }
  194.                 $breadcrumbs = array_reverse( $breadcrumbs );
  195.                 for( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
  196.                     echo $breadcrumbs[$i];
  197.                 }
  198.                 if( $showCurrent == 1 ) {
  199.                     echo $before . get_the_title() . $after;
  200.                 }
  201.  
  202.             }
  203.             elseif( is_tag() ) {
  204.                 echo $before . sprintf( $text['tag'], '<span class="tag-text">', '&nbsp</span>' . single_tag_title( '', false ) ) . $after;
  205.  
  206.             }
  207.             elseif( is_author() ) {
  208.                 global $author;
  209.                 $userdata = get_userdata( $author );
  210.                 echo $before . sprintf( $text['author'], '<span class="author-text">', '&nbsp</span>' . $userdata->display_name ) . $after;
  211.  
  212.             }
  213.             elseif( is_404() ) {
  214.                 echo $before . $text['404'] . $after;
  215.  
  216.             }
  217.             if( get_query_var( 'paged' ) ) {
  218.                 if( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
  219.                     echo ' (';
  220.                 }
  221.                 echo sprintf( __( 'Page %s', 'catch-responsive' ), max( $paged, $page ) );
  222.                 if( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
  223.                     echo ')';
  224.                 }
  225.             }
  226.  
  227.             echo '</div><!-- .wrapper -->
  228.             </div><!-- #breadcrumb-list -->';
  229.         }
  230.  
  231.  
  232.     } // end catchresponsive_breadcrumb_lists
  233. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement