Advertisement
Guest User

template-tags.php

a guest
Apr 22nd, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.44 KB | None | 0 0
  1. // **********************************************************************//
  2. // ! Page title function
  3. // **********************************************************************//
  4.  
  5. if( ! function_exists( 'woodmart_page_title' ) ) {
  6.  
  7. add_action( 'woodmart_after_header', 'woodmart_page_title', 10 );
  8.  
  9. function woodmart_page_title() {
  10. global $wp_query, $post;
  11.  
  12. // Remove page title for dokan store list page
  13.  
  14. if( function_exists( 'dokan_is_store_page' ) && dokan_is_store_page() ) {
  15. return '';
  16. }
  17.  
  18. $page_id = 0;
  19.  
  20. $disable = false;
  21. $page_title = true;
  22. $breadcrumbs = woodmart_get_opt( 'breadcrumbs' );
  23.  
  24. $image = '';
  25.  
  26. $style = '';
  27.  
  28. $page_for_posts = get_option( 'page_for_posts' );
  29. $page_for_shop = get_option( 'woocommerce_shop_page_id' );
  30. $page_for_projects = woodmart_tpl2id( 'portfolio.php' );
  31.  
  32. $title_class = 'page-title-';
  33.  
  34. $title_color = $title_type = $title_size = 'default';
  35.  
  36. // Get default styles from Options Panel
  37. $title_design = woodmart_get_opt( 'page-title-design' );
  38.  
  39. $title_size = woodmart_get_opt( 'page-title-size' );
  40.  
  41. $title_color = woodmart_get_opt( 'page-title-color' );
  42.  
  43. $shop_title = woodmart_get_opt( 'shop_title' );
  44.  
  45. $shop_categories = woodmart_get_opt( 'shop_categories' );
  46.  
  47. $single_post_design = woodmart_get_opt( 'single_post_design' );
  48.  
  49. // Set here page ID. Will be used to get custom value from metabox of specific PAGE | BLOG PAGE | SHOP PAGE.
  50. $page_id = woodmart_page_ID();
  51.  
  52. if( $page_id != 0 ) {
  53. // Get meta value for specific page id
  54. $disable = get_post_meta( $page_id, '_woodmart_title_off', true );
  55.  
  56. $image = get_post_meta( $page_id, '_woodmart_title_image', true );
  57.  
  58. $custom_title_color = get_post_meta( $page_id, '_woodmart_title_color', true );
  59. $custom_title_bg_color = get_post_meta( $page_id, '_woodmart_title_bg_color', true );
  60.  
  61.  
  62. if( $image != '' ) {
  63. $style .= "background-image: url(" . $image . ");";
  64. }
  65.  
  66. if( $custom_title_bg_color != '' ) {
  67. $style .= "background-color: " . $custom_title_bg_color . ";";
  68. }
  69.  
  70. if( $custom_title_color != '' && $custom_title_color != 'default' ) {
  71. $title_color = $custom_title_color;
  72. }
  73. }
  74.  
  75. if ( $title_design == 'disable' ) $page_title = false;
  76.  
  77. if ( ! $page_title && ! $breadcrumbs ) $disable = true;
  78.  
  79. if ( is_single() && $single_post_design == 'large_image' ) $disable = false;
  80.  
  81. if ( $disable ) return;
  82.  
  83. $title_class .= $title_type;
  84. $title_class .= ' title-size-' . $title_size;
  85. $title_class .= ' title-design-' . $title_design;
  86.  
  87. if ( $single_post_design == 'large_image' && is_single() ) {
  88. $title_class .= ' color-scheme-light';
  89. }else{
  90. $title_class .= ' color-scheme-' . $title_color;
  91. }
  92.  
  93. if ( $single_post_design == 'large_image' && is_singular( 'post' ) ) {
  94. $image_url = get_the_post_thumbnail_url( $page_id );
  95. if ( $image_url && ! $style ) $style .= "background-image: url(" . $image_url . ");";
  96. $title_class .= ' post-title-large-image';
  97.  
  98. ?>
  99. <div class="page-title <?php echo esc_attr( $title_class ); ?>" style="<?php echo esc_attr( $style ); ?>">
  100. <div class="container">
  101. <header class="entry-header">
  102. <?php if ( get_the_category_list( ', ' ) ): ?>
  103. <div class="meta-post-categories"><?php echo get_the_category_list( ', ' ); ?></div>
  104. <?php endif ?>
  105.  
  106. <h1 class="entry-title"><?php the_title(); ?></h1>
  107.  
  108. <div class="entry-meta woodmart-entry-meta">
  109. <?php woodmart_post_meta(array(
  110. 'labels' => 1,
  111. 'author' => 1,
  112. 'author_ava' => 1,
  113. 'date' => 1,
  114. 'edit' => 0,
  115. 'comments' => 1,
  116. 'short_labels' => 0
  117. )); ?>
  118. </div>
  119. </header>
  120. </div>
  121. </div>
  122. <?php
  123. return;
  124. }
  125.  
  126. // Heading for pages
  127. if( is_singular( 'page' ) && ( ! $page_for_posts || ! is_page( $page_for_posts ) ) ):
  128. $title = get_the_title();
  129.  
  130. ?>
  131. <div class="page-title <?php echo esc_attr( $title_class ); ?>" style="<?php echo esc_attr( $style ); ?>">
  132. <div class="container">
  133. <header class="entry-header">
  134. <?php if ( woodmart_woocommerce_installed() && ( is_cart() || is_checkout() ) ): ?>
  135. <?php woodmart_checkout_steps(); ?>
  136. <?php else: ?>
  137. <?php if( $page_title ): ?><h1 class="entry-title"><?php echo esc_html( $title ); ?></h1><?php endif; ?>
  138. <?php if ( $breadcrumbs ) woodmart_current_breadcrumbs( 'pages' ); ?>
  139. <?php endif ?>
  140. </header><!-- .entry-header -->
  141. </div>
  142. </div>
  143. <?php
  144. return;
  145. endif;
  146.  
  147.  
  148. // Heading for blog and archives
  149. if( $single_post_design != 'large_image' && is_singular( 'post' ) || woodmart_is_blog_archive() ):
  150.  
  151. $title = ( ! empty( $page_for_posts ) ) ? get_the_title( $page_for_posts ) : esc_html__( 'Blog', 'woodmart' );
  152.  
  153. if( is_tag() ) {
  154. $title = esc_html__( 'Tag Archives: ', 'woodmart') . single_tag_title( '', false ) ;
  155. }
  156.  
  157. if( is_category() ) {
  158. $title = '<span>' . single_cat_title( '', false ) . '</span>';
  159. }
  160.  
  161. if( is_date() ) {
  162. if ( is_day() ) :
  163. $title = esc_html__( 'Daily Archives: ', 'woodmart') . get_the_date();
  164. elseif ( is_month() ) :
  165. $title = esc_html__( 'Monthly Archives: ', 'woodmart') . get_the_date( _x( 'F Y', 'monthly archives date format', 'woodmart' ) );
  166. elseif ( is_year() ) :
  167. $title = esc_html__( 'Yearly Archives: ', 'woodmart') . get_the_date( _x( 'Y', 'yearly archives date format', 'woodmart' ) );
  168. else :
  169. $title = esc_html__( 'Archives', 'woodmart' );
  170. endif;
  171. }
  172.  
  173. if ( is_author() ) {
  174. /*
  175. * Queue the first post, that way we know what author
  176. * we're dealing with (if that is the case).
  177. *
  178. * We reset this later so we can run the loop
  179. * properly with a call to rewind_posts().
  180. */
  181. the_post();
  182.  
  183. $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>';
  184.  
  185. /*
  186. * Since we called the_post() above, we need to
  187. * rewind the loop back to the beginning that way
  188. * we can run the loop properly, in full.
  189. */
  190. rewind_posts();
  191. }
  192.  
  193. if( is_search() ) {
  194. $title = esc_html__( 'Search Results for: ', 'woodmart' ) . get_search_query();
  195. }
  196.  
  197. ?>
  198. <div class="page-title <?php echo esc_attr( $title_class ); ?> title-blog" style="<?php echo esc_attr( $style ); ?>">
  199. <div class="container">
  200. <header class="entry-header">
  201. <?php if( $page_title && is_single() ): ?>
  202. <h3 class="entry-title"><?php echo wp_kses( $title, woodmart_get_allowed_html() ); ?></h3>
  203. <?php elseif( $page_title ): ?>
  204. <h1 class="entry-title"><?php echo wp_kses( $title, woodmart_get_allowed_html() ); ?></h1>
  205. <?php endif; ?>
  206. <?php if ( $breadcrumbs && ! is_search() ) woodmart_current_breadcrumbs( 'pages' ); ?>
  207. </header><!-- .entry-header -->
  208. </div>
  209. </div>
  210. <?php
  211. return;
  212. endif;
  213.  
  214. // Heading for portfolio
  215. if( is_singular( 'portfolio' ) || woodmart_is_portfolio_archive() ):
  216.  
  217. if ( woodmart_get_opt( 'single_portfolio_title_in_page_title' ) ) {
  218. $title = get_the_title();
  219. } else {
  220. $title = get_the_title( $page_for_projects );
  221. }
  222.  
  223. if( is_tax( 'project-cat' ) ) {
  224. $title = single_term_title( '', false );
  225. }
  226.  
  227. ?>
  228. <div class="page-title <?php echo esc_attr( $title_class ); ?> title-blog" style="<?php echo esc_attr( $style ); ?>">
  229. <div class="container">
  230. <header class="entry-header">
  231. <?php if( $page_title ): ?><h1 class="entry-title"><?php echo esc_html( $title ); ?></h1><?php endif; ?>
  232. <?php if ( $breadcrumbs ) woodmart_current_breadcrumbs( 'pages' ); ?>
  233. </header><!-- .entry-header -->
  234. </div>
  235. </div>
  236. <?php
  237. return;
  238. endif;
  239.  
  240. // Page heading for shop page
  241. if( woodmart_is_shop_archive()
  242. && ( $shop_categories || $shop_title )
  243. ):
  244.  
  245. if( is_product_category() ) {
  246.  
  247. $cat = $wp_query->get_queried_object();
  248.  
  249. $cat_image = woodmart_get_category_page_title_image( $cat );
  250.  
  251. if( $cat_image != '') {
  252. $style = "background-image: url(" . $cat_image . ")";
  253. }
  254. }
  255.  
  256. if( is_product_category() || is_product_tag() ) {
  257. $title_class .= ' with-back-btn';
  258. }
  259.  
  260. if( ! $shop_title ) {
  261. $title_class .= ' without-title';
  262. }
  263.  
  264. ?>
  265. <?php if ( apply_filters( 'woocommerce_show_page_title', true ) && ! is_singular( "product" ) ) : ?>
  266. <div class="page-title <?php echo esc_attr( $title_class ); ?> title-shop" style="<?php echo esc_attr( $style ); ?>">
  267. <div class="container">
  268. <div class="nav-shop">
  269.  
  270. <div class="shop-title-wrapper">
  271. <?php if ( is_product_category() || is_product_tag() ): ?>
  272. <?php woodmart_back_btn(); ?>
  273. <?php endif ?>
  274.  
  275. <?php if ( $shop_title ): ?>
  276. <h1 class="entry-title"><?php woocommerce_page_title(); ?></h1>
  277. <?php endif ?>
  278. </div>
  279.  
  280. <?php if( ! is_singular( "product" ) && $shop_categories ) woodmart_product_categories_nav(); ?>
  281.  
  282. </div>
  283. </div>
  284. </div>
  285. <?php endif; ?>
  286.  
  287. <?php
  288.  
  289. return;
  290. endif;
  291. }
  292. }
  293.  
  294. if( ! function_exists( 'woodmart_back_btn' ) ) {
  295. function woodmart_back_btn() {
  296. ?>
  297. <a href="javascript:woodmartThemeModule.backHistory()" class="woodmart-back-btn"><span><?php esc_html_e('Back to products', 'woodmart') ?></span></a>
  298. <?php
  299. }
  300. }
  301.  
  302. // **********************************************************************//
  303. // ! Recursive function to get page title image for the category or
  304. // ! take it from some parent term
  305. // **********************************************************************//
  306.  
  307. if( ! function_exists( 'woodmart_get_category_page_title_image' ) ) {
  308. function woodmart_get_category_page_title_image( $cat ) {
  309. $taxonomy = 'product_cat';
  310. $meta_key = 'title_image';
  311. $cat_image = get_term_meta( $cat->term_id, $meta_key, true );
  312. if( $cat_image != '' ) {
  313. return $cat_image;
  314. } else if( ! empty( $cat->parent ) ) {
  315. $parent = get_term_by( 'term_id', $cat->parent, $taxonomy );
  316. return woodmart_get_category_page_title_image( $parent );
  317. } else {
  318. return '';
  319. }
  320. }
  321. }
  322.  
  323.  
  324.  
  325. // **********************************************************************//
  326. // ! Breacdrumbs function
  327. // ! Snippet from http://dimox.net/wordpress-breadcrumbs-without-a-plugin/
  328. // **********************************************************************//
  329.  
  330. if( ! function_exists( 'woodmart_breadcrumbs' ) ) {
  331. function woodmart_breadcrumbs() {
  332.  
  333. /* === OPTIONS === */
  334. $text['home'] = esc_html__('Home', 'woodmart'); // text for the 'Home' link
  335. $text['category'] = esc_html__('Archive by Category "%s"', 'woodmart'); // text for a category page
  336. $text['search'] = esc_html__('Search Results for "%s" Query', 'woodmart'); // text for a search results page
  337. $text['tag'] = esc_html__('Posts Tagged "%s"', 'woodmart'); // text for a tag page
  338. $text['author'] = esc_html__('Articles Posted by %s', 'woodmart'); // text for an author page
  339. $text['404'] = esc_html__('Error 404', 'woodmart'); // text for the 404 page
  340.  
  341. $show_current_post = 0; // 1 - show current post
  342. $show_current = 1; // 1 - show current post/page/category title in breadcrumbs, 0 - don't show
  343. $show_on_home = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
  344. $show_home_link = 1; // 1 - show the 'Home' link, 0 - don't show
  345. $show_title = 1; // 1 - show the title for the links, 0 - don't show
  346. $delimiter = ' &raquo; '; // delimiter between crumbs
  347. $before = '<span class="current">'; // tag before the current crumb
  348. $after = '</span>'; // tag after the current crumb
  349. /* === END OF OPTIONS === */
  350.  
  351. global $post;
  352.  
  353. $home_link = home_url('/');
  354. $link_before = '<span typeof="v:Breadcrumb">';
  355. $link_after = '</span>';
  356. $link_attr = ' rel="v:url" property="v:title"';
  357. $link = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after;
  358. $parent_id = $parent_id_2 = ( ! empty($post) && is_a($post, 'WP_Post') ) ? $post->post_parent : 0;
  359. $frontpage_id = get_option('page_on_front');
  360. $projects_id = woodmart_tpl2id( 'portfolio.php' );
  361.  
  362. if (is_home() || is_front_page()) {
  363.  
  364. if ($show_on_home == 1) echo '<div class="breadcrumbs"><a href="' . $home_link . '">' . $text['home'] . '</a></div>';
  365.  
  366. } else {
  367.  
  368. echo '<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">';
  369. if ($show_home_link == 1) {
  370. echo '<a href="' . $home_link . '" rel="v:url" property="v:title">' . $text['home'] . '</a>';
  371. if ($frontpage_id == 0 || $parent_id != $frontpage_id) echo esc_html( $delimiter );
  372. }
  373.  
  374. if ( is_category() ) {
  375. $this_cat = get_category(get_query_var('cat'), false);
  376. if ($this_cat->parent != 0) {
  377. $cats = get_category_parents($this_cat->parent, TRUE, $delimiter);
  378. if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
  379. $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
  380. $cats = str_replace('</a>', '</a>' . $link_after, $cats);
  381. if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
  382. echo wp_kses_post( $cats );
  383. }
  384. if ($show_current == 1) echo wp_kses_post( $before ) . sprintf($text['category'], single_cat_title('', false)) . wp_kses_post( $after );
  385.  
  386. } elseif( is_tax( 'project-cat' ) ) {
  387. printf($link, get_the_permalink( $projects_id ), get_the_title( $projects_id ));
  388. } elseif ( is_search() ) {
  389. echo wp_kses_post( $before ) . sprintf($text['search'], get_search_query()) . wp_kses_post( $after );
  390.  
  391. } elseif ( is_day() ) {
  392. echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
  393. echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
  394. echo wp_kses_post( $before ) . get_the_time('d') . wp_kses_post( $after );
  395.  
  396. } elseif ( is_month() ) {
  397. echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
  398. echo wp_kses_post( $before ) . get_the_time('F') . wp_kses_post( $after );
  399.  
  400. } elseif ( is_year() ) {
  401. echo wp_kses_post( $before ) . get_the_time('Y') . wp_kses_post( $after );
  402.  
  403. } elseif ( is_single() && !is_attachment() ) {
  404. if( get_post_type() == 'portfolio' ) {
  405. printf($link, get_the_permalink( $projects_id ), get_the_title( $projects_id ));
  406. if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
  407.  
  408. } else if ( get_post_type() != 'post' ) {
  409. $post_type = get_post_type_object(get_post_type());
  410. $slug = $post_type->rewrite;
  411. printf($link, $home_link . $slug['slug'] . '/', $post_type->labels->singular_name);
  412. if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
  413. } else {
  414. $cat = get_the_category();
  415. if ( $cat && isset( $cat[0] ) ) {
  416. $cat = $cat[0];
  417. $cats = get_category_parents($cat, TRUE, $delimiter);
  418. if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
  419. $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
  420. $cats = str_replace('</a>', '</a>' . $link_after, $cats);
  421. if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
  422. echo wp_kses_post( $cats );
  423. if ($show_current_post == 1) echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
  424. }
  425. }
  426.  
  427. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  428. $post_type = get_post_type_object(get_post_type());
  429. if ( is_object( $post_type ) ) {
  430. echo wp_kses_post( $before ) . $post_type->labels->singular_name . wp_kses_post( $after );
  431. }
  432.  
  433. } elseif ( is_attachment() ) {
  434. $parent = get_post($parent_id);
  435. $cat = get_the_category($parent->ID); $cat = $cat[0];
  436. if ($cat) {
  437. $cats = get_category_parents($cat, TRUE, $delimiter);
  438. $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);
  439. $cats = str_replace('</a>', '</a>' . $link_after, $cats);
  440. if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
  441. echo wp_kses_post( $cats );
  442. }
  443. printf($link, get_permalink($parent), $parent->post_title);
  444. if ($show_current == 1) echo esc_html( $delimiter ) . $before . get_the_title() . $after;
  445.  
  446. } elseif ( is_page() && !$parent_id ) {
  447. if ($show_current == 1) echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
  448.  
  449. } elseif ( is_page() && $parent_id ) {
  450. if ($parent_id != $frontpage_id) {
  451. $breadcrumbs = array();
  452. while ($parent_id) {
  453. $page = get_page($parent_id);
  454. if ($parent_id != $frontpage_id) {
  455. $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
  456. }
  457. $parent_id = $page->post_parent;
  458. }
  459. $breadcrumbs = array_reverse($breadcrumbs);
  460. for ($i = 0; $i < count($breadcrumbs); $i++) {
  461. echo wp_kses_post( $breadcrumbs[$i] );
  462. if ($i != count($breadcrumbs)-1) echo esc_html( $delimiter );
  463. }
  464. }
  465. if ($show_current == 1) {
  466. if ($show_home_link == 1 || ($parent_id_2 != 0 && $parent_id_2 != $frontpage_id)) echo esc_html( $delimiter );
  467. echo wp_kses_post( $before ) . get_the_title() . wp_kses_post( $after );
  468. }
  469.  
  470. } elseif ( is_tag() ) {
  471. echo wp_kses_post( $before ) . sprintf($text['tag'], single_tag_title('', false)) . wp_kses_post( $after );
  472.  
  473. } elseif ( is_author() ) {
  474. global $author;
  475. $userdata = get_userdata($author);
  476. echo wp_kses_post( $before ) . sprintf($text['author'], $userdata->display_name) . wp_kses_post( $after );
  477.  
  478. } elseif ( is_404() ) {
  479. echo wp_kses_post( $before ) . $text['404'] . wp_kses_post( $after );
  480.  
  481. } elseif ( has_post_format() && !is_singular() ) {
  482. echo get_post_format_string( get_post_format() );
  483. }
  484.  
  485. if ( get_query_var('paged') ) {
  486. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  487. echo esc_html__('Page', 'woodmart' ) . ' ' . get_query_var('paged');
  488. if ( is_category() || is_day() ||
  489. is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  490. }
  491.  
  492. echo '</div><!-- .breadcrumbs -->';
  493.  
  494. }
  495. }
  496. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement