Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // **********************************************************************//
- // ! Page title function
- // **********************************************************************//
- if( ! function_exists( 'woodmart_page_title' ) ) {
- add_action( 'woodmart_after_header', 'woodmart_page_title', 10 );
- function woodmart_page_title() {
- global $wp_query, $post;
- // Remove page title for dokan store list page
- if( function_exists( 'dokan_is_store_page' ) && dokan_is_store_page() ) {
- return '';
- }
- $page_id = 0;
- $disable = false;
- $page_title = true;
- $breadcrumbs = woodmart_get_opt( 'breadcrumbs' );
- $image = '';
- $style = '';
- $page_for_posts = get_option( 'page_for_posts' );
- $page_for_shop = get_option( 'woocommerce_shop_page_id' );
- $page_for_projects = woodmart_tpl2id( 'portfolio.php' );
- $title_class = 'page-title-';
- $title_color = $title_type = $title_size = 'default';
- // Get default styles from Options Panel
- $title_design = woodmart_get_opt( 'page-title-design' );
- $title_size = woodmart_get_opt( 'page-title-size' );
- $title_color = woodmart_get_opt( 'page-title-color' );
- $shop_title = woodmart_get_opt( 'shop_title' );
- $shop_categories = woodmart_get_opt( 'shop_categories' );
- $single_post_design = woodmart_get_opt( 'single_post_design' );
- // Set here page ID. Will be used to get custom value from metabox of specific PAGE | BLOG PAGE | SHOP PAGE.
- $page_id = woodmart_page_ID();
- if( $page_id != 0 ) {
- // Get meta value for specific page id
- $disable = get_post_meta( $page_id, '_woodmart_title_off', true );
- $image = get_post_meta( $page_id, '_woodmart_title_image', true );
- $custom_title_color = get_post_meta( $page_id, '_woodmart_title_color', true );
- $custom_title_bg_color = get_post_meta( $page_id, '_woodmart_title_bg_color', true );
- if( $image != '' ) {
- $style .= "background-image: url(" . $image . ");";
- }
- if( $custom_title_bg_color != '' ) {
- $style .= "background-color: " . $custom_title_bg_color . ";";
- }
- if( $custom_title_color != '' && $custom_title_color != 'default' ) {
- $title_color = $custom_title_color;
- }
- }
- if ( $title_design == 'disable' ) $page_title = false;
- if ( ! $page_title && ! $breadcrumbs ) $disable = true;
- if ( is_single() && $single_post_design == 'large_image' ) $disable = false;
- if ( $disable ) return;
- $title_class .= $title_type;
- $title_class .= ' title-size-' . $title_size;
- $title_class .= ' title-design-' . $title_design;
- if ( $single_post_design == 'large_image' && is_single() ) {
- $title_class .= ' color-scheme-light';
- }else{
- $title_class .= ' color-scheme-' . $title_color;
- }
- if ( $single_post_design == 'large_image' && is_singular( 'post' ) ) {
- $image_url = get_the_post_thumbnail_url( $page_id );
- if ( $image_url && ! $style ) $style .= "background-image: url(" . $image_url . ");";
- $title_class .= ' post-title-large-image';
- ?>
- <div class="page-title <?php echo esc_attr( $title_class ); ?>" style="<?php echo esc_attr( $style ); ?>">
- <div class="container">
- <header class="entry-header">
- <?php if ( get_the_category_list( ', ' ) ): ?>
- <div class="meta-post-categories"><?php echo get_the_category_list( ', ' ); ?></div>
- <?php endif ?>
- <h1 class="entry-title"><?php the_title(); ?></h1>
- <div class="entry-meta woodmart-entry-meta">
- <?php woodmart_post_meta(array(
- 'labels' => 1,
- 'author' => 1,
- 'author_ava' => 1,
- 'date' => 1,
- 'edit' => 0,
- 'comments' => 1,
- 'short_labels' => 0
- )); ?>
- </div>
- </header>
- </div>
- </div>
- <?php
- return;
- }
- // Heading for pages
- if( is_singular( 'page' ) && ( ! $page_for_posts || ! is_page( $page_for_posts ) ) ):
- $title = get_the_title();
- ?>
- <div class="page-title <?php echo esc_attr( $title_class ); ?>" style="<?php echo esc_attr( $style ); ?>">
- <div class="container">
- <header class="entry-header">
- <?php if ( woodmart_woocommerce_installed() && ( is_cart() || is_checkout() ) ): ?>
- <?php woodmart_checkout_steps(); ?>
- <?php else: ?>
- <?php if( $page_title ): ?><h1 class="entry-title"><?php echo esc_html( $title ); ?></h1><?php endif; ?>
- <?php if ( $breadcrumbs ) woodmart_current_breadcrumbs( 'pages' ); ?>
- <?php endif ?>
- </header><!-- .entry-header -->
- </div>
- </div>
- <?php
- return;
- endif;
- // Heading for blog and archives
- if( $single_post_design != 'large_image' && is_singular( 'post' ) || woodmart_is_blog_archive() ):
- $title = ( ! empty( $page_for_posts ) ) ? get_the_title( $page_for_posts ) : esc_html__( 'Blog', 'woodmart' );
- if( is_tag() ) {
- $title = esc_html__( 'Tag Archives: ', 'woodmart') . single_tag_title( '', false ) ;
- }
- if( is_category() ) {
- $title = '<span>' . single_cat_title( '', false ) . '</span>';
- }
- if( is_date() ) {
- if ( is_day() ) :
- $title = esc_html__( 'Daily Archives: ', 'woodmart') . get_the_date();
- elseif ( is_month() ) :
- $title = esc_html__( 'Monthly Archives: ', 'woodmart') . get_the_date( _x( 'F Y', 'monthly archives date format', 'woodmart' ) );
- elseif ( is_year() ) :
- $title = esc_html__( 'Yearly Archives: ', 'woodmart') . get_the_date( _x( 'Y', 'yearly archives date format', 'woodmart' ) );
- else :
- $title = esc_html__( 'Archives', 'woodmart' );
- endif;
- }
- if ( is_author() ) {
- /*
- * Queue the first post, that way we know what author
- * we're dealing with (if that is the case).
- *
- * We reset this later so we can run the loop
- * properly with a call to rewind_posts().
- */
- the_post();
- $title = esc_html__( 'Posts by ', 'woodmart' ) . '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>';
- /*
- * Since we called the_post() above, we need to
- * rewind the loop back to the beginning that way
- * we can run the loop properly, in full.
- */
- rewind_posts();
- }
- if( is_search() ) {
- $title = esc_html__( 'Search Results for: ', 'woodmart' ) . get_search_query();
- }
- ?>
- <div class="page-title <?php echo esc_attr( $title_class ); ?> title-blog" style="<?php echo esc_attr( $style ); ?>">
- <div class="container">
- <header class="entry-header">
- <?php if( $page_title && is_single() ): ?>
- <h3 class="entry-title"><?php echo wp_kses( $title, woodmart_get_allowed_html() ); ?></h3>
- <?php elseif( $page_title ): ?>
- <h1 class="entry-title"><?php echo wp_kses( $title, woodmart_get_allowed_html() ); ?></h1>
- <?php endif; ?>
- <?php if ( $breadcrumbs && ! is_search() ) woodmart_current_breadcrumbs( 'pages' ); ?>
- </header><!-- .entry-header -->
- </div>
- </div>
- <?php
- return;
- endif;
- // Heading for portfolio
- if( is_singular( 'portfolio' ) || woodmart_is_portfolio_archive() ):
- if ( woodmart_get_opt( 'single_portfolio_title_in_page_title' ) ) {
- $title = get_the_title();
- } else {
- $title = get_the_title( $page_for_projects );
- }
- if( is_tax( 'project-cat' ) ) {
- $title = single_term_title( '', false );
- }
- ?>
- <div class="page-title <?php echo esc_attr( $title_class ); ?> title-blog" style="<?php echo esc_attr( $style ); ?>">
- <div class="container">
- <header class="entry-header">
- <?php if( $page_title ): ?><h1 class="entry-title"><?php echo esc_html( $title ); ?></h1><?php endif; ?>
- <?php if ( $breadcrumbs ) woodmart_current_breadcrumbs( 'pages' ); ?>
- </header><!-- .entry-header -->
- </div>
- </div>
- <?php
- return;
- endif;
- // Page heading for shop page
- if( woodmart_is_shop_archive()
- && ( $shop_categories || $shop_title )
- ):
- if( is_product_category() ) {
- $cat = $wp_query->get_queried_object();
- $cat_image = woodmart_get_category_page_title_image( $cat );
- if( $cat_image != '') {
- $style = "background-image: url(" . $cat_image . ")";
- }
- }
- if( is_product_category() || is_product_tag() ) {
- $title_class .= ' with-back-btn';
- }
- if( ! $shop_title ) {
- $title_class .= ' without-title';
- }
- ?>
- <?php if ( apply_filters( 'woocommerce_show_page_title', true ) && ! is_singular( "product" ) ) : ?>
- <div class="page-title <?php echo esc_attr( $title_class ); ?> title-shop" style="<?php echo esc_attr( $style ); ?>">
- <div class="container">
- <div class="nav-shop">
- <div class="shop-title-wrapper">
- <?php if ( is_product_category() || is_product_tag() ): ?>
- <?php woodmart_back_btn(); ?>
- <?php endif ?>
- <?php if ( $shop_title ): ?>
- <h1 class="entry-title"><?php woocommerce_page_title(); ?></h1>
- <?php endif ?>
- </div>
- <?php if( ! is_singular( "product" ) && $shop_categories ) woodmart_product_categories_nav(); ?>
- </div>
- </div>
- </div>
- <?php endif; ?>
- <?php
- return;
- endif;
- }
- }
- if( ! function_exists( 'woodmart_back_btn' ) ) {
- function woodmart_back_btn() {
- ?>
- <a href="javascript:woodmartThemeModule.backHistory()" class="woodmart-back-btn"><span><?php esc_html_e('Back to products', 'woodmart') ?></span></a>
- <?php
- }
- }
- // **********************************************************************//
- // ! Recursive function to get page title image for the category or
- // ! take it from some parent term
- // **********************************************************************//
- if( ! function_exists( 'woodmart_get_category_page_title_image' ) ) {
- function woodmart_get_category_page_title_image( $cat ) {
- $taxonomy = 'product_cat';
- $meta_key = 'title_image';
- $cat_image = get_term_meta( $cat->term_id, $meta_key, true );
- if( $cat_image != '' ) {
- return $cat_image;
- } else if( ! empty( $cat->parent ) ) {
- $parent = get_term_by( 'term_id', $cat->parent, $taxonomy );
- return woodmart_get_category_page_title_image( $parent );
- } else {
- return '';
- }
- }
- }
- // **********************************************************************//
- // ! Breacdrumbs function
- // ! Snippet from http://dimox.net/wordpress-breadcrumbs-without-a-plugin/
- // **********************************************************************//
- if( ! function_exists( 'woodmart_breadcrumbs' ) ) {
- function woodmart_breadcrumbs() {
- /* === OPTIONS === */
- $text['home'] = esc_html__('Home', 'woodmart'); // text for the 'Home' link
- $text['category'] = esc_html__('Archive by Category "%s"', 'woodmart'); // text for a category page
- $text['search'] = esc_html__('Search Results for "%s" Query', 'woodmart'); // text for a search results page
- $text['tag'] = esc_html__('Posts Tagged "%s"', 'woodmart'); // text for a tag page
- $text['author'] = esc_html__('Articles Posted by %s', 'woodmart'); // text for an author page
- $text['404'] = esc_html__('Error 404', 'woodmart'); // text for the 404 page
- $show_current_post = 0; // 1 - show current post
- $show_current = 1; // 1 - show current post/page/category title in breadcrumbs, 0 - don't show
- $show_on_home = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
- $show_home_link = 1; // 1 - show the 'Home' link, 0 - don't show
- $show_title = 1; // 1 - show the title for the links, 0 - don't show
- $delimiter = ' » '; // delimiter between crumbs
- $before = '<span class="current">'; // tag before the current crumb
- $after = '</span>'; // tag after the current crumb
- /* === END OF OPTIONS === */
- global $post;
- $home_link = home_url('/');
- $link_before = '<span typeof="v:Breadcrumb">';
- $link_after = '</span>';
- $link_attr = ' rel="v:url" property="v:title"';
- $link = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after;
- $parent_id = $parent_id_2 = ( ! empty($post) && is_a($post, 'WP_Post') ) ? $post->post_parent : 0;
- $frontpage_id = get_option('page_on_front');
- $projects_id = woodmart_tpl2id( 'portfolio.php' );
- if (is_home() || is_front_page()) {
- if ($show_on_home == 1) echo '<div class="breadcrumbs"><a href="' . $home_link . '">' . $text['home'] . '</a></div>';
- } else {
- echo '<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">';
- if ($show_home_link == 1) {
- echo '<a href="' . $home_link . '" rel="v:url" property="v:title">' . $text['home'] . '</a>';
- if ($frontpage_id == 0 || $parent_id != $frontpage_id) echo esc_html( $delimiter );
- }
- if ( is_category() ) {
- $this_cat = get_category(get_query_var('cat'), false);
- if ($this_cat->parent != 0) {
- $cats = get_category_parents($this_cat->parent, TRUE, $delimiter);
- if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
- $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
- $cats = str_replace('</a>', '</a>' . $link_after, $cats);
- if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
- echo wp_kses_post( $cats );
- }
- if ($show_current == 1) echo wp_kses_post( $before ) . sprintf($text['category'], single_cat_title('', false)) . wp_kses_post( $after );
- } elseif( is_tax( 'project-cat' ) ) {
- printf($link, get_the_permalink( $projects_id ), get_the_title( $projects_id ));
- } elseif ( is_search() ) {
- echo wp_kses_post( $before ) . sprintf($text['search'], get_search_query()) . wp_kses_post( $after );
- } elseif ( is_day() ) {
- echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
- echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
- echo wp_kses_post( $before ) . get_the_time('d') . wp_kses_post( $after );
- } elseif ( is_month() ) {
- echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
- echo wp_kses_post( $before ) . get_the_time('F') . wp_kses_post( $after );
- } elseif ( is_year() ) {
- echo wp_kses_post( $before ) . get_the_time('Y') . wp_kses_post( $after );
- } elseif ( is_single() && !is_attachment() ) {
- if( get_post_type() == 'portfolio' ) {
- printf($link, get_the_permalink( $projects_id ), get_the_title( $projects_id ));
- if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
- } else if ( get_post_type() != 'post' ) {
- $post_type = get_post_type_object(get_post_type());
- $slug = $post_type->rewrite;
- printf($link, $home_link . $slug['slug'] . '/', $post_type->labels->singular_name);
- if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
- } else {
- $cat = get_the_category();
- if ( $cat && isset( $cat[0] ) ) {
- $cat = $cat[0];
- $cats = get_category_parents($cat, TRUE, $delimiter);
- if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
- $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
- $cats = str_replace('</a>', '</a>' . $link_after, $cats);
- if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
- echo wp_kses_post( $cats );
- if ($show_current_post == 1) echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
- }
- }
- } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
- $post_type = get_post_type_object(get_post_type());
- if ( is_object( $post_type ) ) {
- echo wp_kses_post( $before ) . $post_type->labels->singular_name . wp_kses_post( $after );
- }
- } elseif ( is_attachment() ) {
- $parent = get_post($parent_id);
- $cat = get_the_category($parent->ID); $cat = $cat[0];
- if ($cat) {
- $cats = get_category_parents($cat, TRUE, $delimiter);
- $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
- $cats = str_replace('</a>', '</a>' . $link_after, $cats);
- if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
- echo wp_kses_post( $cats );
- }
- printf($link, get_permalink($parent), $parent->post_title);
- if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
- } elseif ( is_page() && !$parent_id ) {
- if ($show_current == 1) echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
- } elseif ( is_page() && $parent_id ) {
- if ($parent_id != $frontpage_id) {
- $breadcrumbs = array();
- while ($parent_id) {
- $page = get_page($parent_id);
- if ($parent_id != $frontpage_id) {
- $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
- }
- $parent_id = $page->post_parent;
- }
- $breadcrumbs = array_reverse($breadcrumbs);
- for ($i = 0; $i < count($breadcrumbs); $i++) {
- echo wp_kses_post( $breadcrumbs[$i] );
- if ($i != count($breadcrumbs)-1) echo esc_html( $delimiter );
- }
- }
- if ($show_current == 1) {
- if ($show_home_link == 1 || ($parent_id_2 != 0 && $parent_id_2 != $frontpage_id)) echo esc_html( $delimiter );
- echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
- }
- } elseif ( is_tag() ) {
- echo wp_kses_post( $before ) . sprintf($text['tag'], single_tag_title('', false)) . wp_kses_post( $after );
- } elseif ( is_author() ) {
- global $author;
- $userdata = get_userdata($author);
- echo wp_kses_post( $before ) . sprintf($text['author'], $userdata->display_name) . wp_kses_post( $after );
- } elseif ( is_404() ) {
- echo wp_kses_post( $before ) . $text['404'] . wp_kses_post( $after );
- } elseif ( has_post_format() && !is_singular() ) {
- echo get_post_format_string( get_post_format() );
- }
- if ( get_query_var('paged') ) {
- if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
- echo esc_html__('Page', 'woodmart' ) . ' ' . get_query_var('paged');
- if ( is_category() || is_day() ||
- is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
- }
- echo '</div><!-- .breadcrumbs -->';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement