Advertisement
zebrawebdesigns

header-extensions.php

Jun 11th, 2013
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.29 KB | None | 0 0
  1. <?php
  2. /**
  3. * Adds header structures.
  4. *
  5. * @package Theme Horse
  6. * @subpackage Attitude
  7. * @since Attitude 1.0
  8. * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
  9. * @link http://themehorse.com/themes/attitude
  10. */
  11.  
  12. /****************************************************************************************/
  13.  
  14. add_action( 'attitude_title', 'attitude_add_meta', 5 );
  15. /**
  16. * Add meta tags.
  17. */
  18. function attitude_add_meta() {
  19. ?>
  20. <meta charset="<?php bloginfo( 'charset' ); ?>" />
  21. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  22. <?php
  23. }
  24.  
  25. /****************************************************************************************/
  26.  
  27. add_action( 'attitude_title', 'attitude_show_title', 10 );
  28. /**
  29. * Showing the title in the browser tab.
  30. *
  31. * @uses wp_title() Display the title on the browser tab.
  32. */
  33. function attitude_show_title() {
  34. ?>
  35. <title>
  36. <?php
  37. /**
  38. * Print the <title> tag based on what is being viewed.
  39. */
  40. wp_title( '|', true, 'right' );
  41. ?>
  42. </title>
  43. <?php
  44. }
  45.  
  46. add_filter( 'wp_title', 'attitude_filter_wp_title' );
  47. /**
  48. * Modifying the Title
  49. *
  50. * Function tied to the wp_title filter hook.
  51. * @uses filter wp_title
  52. */
  53. function attitude_filter_wp_title( $title ) {
  54. global $page, $paged;
  55.  
  56. // Get the Site Name
  57. $site_name = get_bloginfo( 'name' );
  58.  
  59. // Get the Site Description
  60. $site_description = get_bloginfo( 'description' );
  61.  
  62. $filtered_title = '';
  63.  
  64. // For Homepage or Frontpage
  65. if( is_home() || is_front_page() ) {
  66. $filtered_title .= $site_name;
  67. if ( !empty( $site_description ) ) {
  68. $filtered_title .= ' &#124; '. $site_description;
  69. }
  70. }
  71. elseif( is_feed() ) {
  72. $filtered_title = '';
  73. }
  74. else{
  75. $filtered_title = $title . $site_name;
  76. }
  77.  
  78. // Add a page number if necessary:
  79. if( $paged >= 2 || $page >= 2 ) {
  80. $filtered_title .= ' &#124; ' . sprintf( __( 'Page %s', 'attitude' ), max( $paged, $page ) );
  81. }
  82.  
  83. // Return the modified title
  84. return $filtered_title;
  85. }
  86.  
  87. /****************************************************************************************/
  88.  
  89. add_action( 'attitude_links', 'attitude_add_links', 10 );
  90. /**
  91. * Adding link to stylesheet file
  92. *
  93. * @uses get_stylesheet_uri()
  94. */
  95. function attitude_add_links() {
  96. ?>
  97. <link rel="profile" href="http://gmpg.org/xfn/11" />
  98. <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
  99. <?php
  100. }
  101.  
  102. /****************************************************************************************/
  103.  
  104. // Load Favicon in Header Section
  105. add_action( 'attitude_links', 'attitude_favicon', 15 );
  106. // Load Favicon in Admin Section
  107. add_action( 'admin_head', 'attitude_favicon' );
  108. /**
  109. * Get the favicon Image from theme options
  110. * display favicon
  111. *
  112. * @uses set_transient and delete_transient
  113. */
  114. function attitude_favicon() {
  115.  
  116. $attitude_favicon = '';
  117. if( ( !$attitude_favicon = get_transient( 'attitude_favicon' ) ) ) {
  118. global $attitude_theme_options_settings;
  119. $options = $attitude_theme_options_settings;
  120.  
  121. if ( "0" == $options[ 'disable_favicon' ] ) {
  122. if ( !empty( $options[ 'favicon' ] ) ) {
  123. $attitude_favicon .= '<link rel="shortcut icon" href="'.esc_url( $options[ 'favicon' ] ).'" type="image/x-icon" />';
  124. }
  125. }
  126.  
  127. set_transient( 'attitude_favicon', $attitude_favicon, 86940 );
  128. }
  129. echo $attitude_favicon ;
  130. }
  131.  
  132. /****************************************************************************************/
  133.  
  134. // Load webpageicon in Header Section
  135. add_action( 'attitude_links', 'attitude_webpageicon', 20 );
  136. /**
  137. * Get the webpageicon Image from theme options
  138. * display webpageicon
  139. *
  140. * @uses set_transient and delete_transient
  141. */
  142. function attitude_webpageicon() {
  143.  
  144. $attitude_webpageicon = '';
  145. if( ( !$attitude_webpageicon = get_transient( 'attitude_webpageicon' ) ) ) {
  146. global $attitude_theme_options_settings;
  147. $options = $attitude_theme_options_settings;
  148.  
  149. if ( "0" == $options[ 'disable_webpageicon' ] ) {
  150. if ( !empty( $options[ 'webpageicon' ] ) ) {
  151. $attitude_webpageicon .= '<link rel="apple-touch-icon-precomposed" href="'.esc_url( $options[ 'webpageicon' ] ).'" />';
  152. }
  153. }
  154.  
  155. set_transient( 'attitude_webpageicon', $attitude_webpageicon, 86940 );
  156. }
  157. echo $attitude_webpageicon ;
  158. }
  159.  
  160. /****************************************************************************************/
  161.  
  162. add_action( 'attitude_header', 'attitude_headerdetails', 10 );
  163. /**
  164. * Shows Header Part Content
  165. *
  166. * Shows the site logo, title, description, searchbar, social icons etc.
  167. */
  168. function attitude_headerdetails() {
  169. ?>
  170. <?php
  171. global $attitude_theme_options_settings;
  172. $options = $attitude_theme_options_settings;
  173.  
  174. $elements = array();
  175. $elements = array( $options[ 'social_facebook' ],
  176. $options[ 'social_twitter' ],
  177. $options[ 'social_googleplus' ],
  178. $options[ 'social_linkedin' ],
  179. $options[ 'social_pinterest' ],
  180. $options[ 'social_youtube' ],
  181. $options[ 'social_vimeo' ],
  182. $options[ 'social_flickr' ],
  183. $options[ 'social_tumblr' ],
  184. $options[ 'social_myspace' ],
  185. $options[ 'social_rss' ]
  186. );
  187.  
  188. $flag = 0;
  189. if( !empty( $elements ) ) {
  190. foreach( $elements as $option) {
  191. if( !empty( $option ) ) {
  192. $flag = 1;
  193. }
  194. else {
  195. $flag = 0;
  196. }
  197. if( 1 == $flag ) {
  198. break;
  199. }
  200. }
  201. }
  202. ?>
  203.  
  204. <div class="container clearfix">
  205. <div class="hgroup-wrap clearfix">
  206. <?php
  207. if( 0 == $options[ 'hide_header_searchform' ] || 1 == $flag ) {
  208. ?>
  209. <section class="hgroup-right">
  210. <?php attitude_socialnetworks( $flag ); ?>
  211. <?php if( 0 == $options[ 'hide_header_searchform' ] ) get_search_form(); ?>
  212. </section><!-- .hgroup-right -->
  213. <?php
  214. }
  215. ?>
  216. <hgroup id="site-logo" class="clearfix">
  217. <?php
  218. if( $options[ 'header_show' ] != 'disable-both' && $options[ 'header_show' ] == 'header-text' ) {
  219. ?>
  220. <h1 id="site-title">
  221. <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
  222. <?php bloginfo( 'name' ); ?>
  223. </a>
  224. </h1>
  225. <h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
  226. <?php
  227. }
  228. elseif( $options[ 'header_show' ] != 'disable-both' && $options[ 'header_show' ] == 'header-logo' ) {
  229. ?>
  230. <h1 id="site-title">
  231. <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
  232. <img src="<?php echo $options[ 'header_logo' ]; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
  233. </a>
  234. </h1>
  235. <?php
  236. }
  237. ?>
  238.  
  239. </hgroup><!-- #site-logo -->
  240.  
  241. </div><!-- .hgroup-wrap -->
  242. </div><!-- .container -->
  243. <?php $header_image = get_header_image();
  244. if( !empty( $header_image ) ) :?>
  245. <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
  246. <?php endif; ?>
  247. <?php
  248. if ( has_nav_menu( 'primary' ) ) {
  249. $args = array(
  250. 'theme_location' => 'primary',
  251. 'container' => '',
  252. 'items_wrap' => '<ul class="root">%3$s</ul>'
  253. );
  254. echo '<nav id="access" class="clearfix">
  255. <div class="container clearfix">';
  256. wp_nav_menu( $args );
  257. echo '</div><!-- .container -->
  258. </nav><!-- #access -->';
  259. }
  260. else {
  261. echo '<nav id="access" class="clearfix">
  262. <div class="container clearfix">';
  263. wp_page_menu( array( 'menu_class' => 'root' ) );
  264. echo '</div><!-- .container -->
  265. </nav><!-- #access -->';
  266. }
  267. ?>
  268. <?php
  269. if( 'above-slider' == $options[ 'slogan_position' ] && ( is_home() || is_front_page() ) )
  270. if( function_exists( 'attitude_home_slogan' ) )
  271. attitude_home_slogan();
  272.  
  273. if( is_home() || is_front_page() ) {
  274. if( "0" == $options[ 'disable_slider' ] ) {
  275. if( function_exists( 'attitude_pass_cycle_parameters' ) )
  276. attitude_pass_cycle_parameters();
  277. if( function_exists( 'attitude_featured_post_slider' ) )
  278. attitude_featured_post_slider();
  279. }
  280. }
  281. else {
  282. if( ( '' != attitude_header_title() ) || function_exists( 'bcn_display_list' ) ) {
  283. ?>
  284. <div class="page-title-wrap">
  285. <div class="container clearfix">
  286. <?php
  287. if( function_exists( 'attitude_breadcrumb' ) )
  288. attitude_breadcrumb();
  289. ?>
  290. <h3 class="page-title"><?php echo attitude_header_title(); ?></h3><!-- .page-title -->
  291. </div>
  292. </div>
  293. <?php
  294. }
  295. }
  296. if( 'below-slider' == $options[ 'slogan_position' ] && ( is_home() || is_front_page() ) )
  297. if( function_exists( 'attitude_home_slogan' ) )
  298. attitude_home_slogan();
  299.  
  300. }
  301.  
  302. /****************************************************************************************/
  303.  
  304. if ( ! function_exists( 'attitude_socialnetworks' ) ) :
  305. /**
  306. * This function for social links display on header
  307. *
  308. * Get links through Theme Options
  309. */
  310. function attitude_socialnetworks( $flag ) {
  311.  
  312. global $attitude_theme_options_settings;
  313. $options = $attitude_theme_options_settings;
  314.  
  315. $attitude_socialnetworks = '';
  316. if ( ( !$attitude_socialnetworks = get_transient( 'attitude_socialnetworks' ) ) && ( 1 == $flag ) ) {
  317.  
  318. $attitude_socialnetworks .='
  319. <div class="social-profiles clearfix">
  320. <ul>';
  321.  
  322. $social_links = array();
  323. $social_links = array( 'Facebook' => 'social_facebook',
  324. 'Twitter' => 'social_twitter',
  325. 'Google-Plus' => 'social_googleplus',
  326. 'Pinterest' => 'social_pinterest',
  327. 'You-tube' => 'social_youtube',
  328. 'Vimeo' => 'social_vimeo',
  329. 'Linked' => 'social_linkedin',
  330. 'Flickr' => 'social_flickr',
  331. 'Tumblr' => 'social_tumblr',
  332. 'My-Space' => 'social_myspace',
  333. 'RSS' => 'social_rss'
  334. );
  335.  
  336. foreach( $social_links as $key => $value ) {
  337. if ( !empty( $options[ $value ] ) ) {
  338. $attitude_socialnetworks .=
  339. '<li class="'.strtolower($key).'"><a href="'.esc_url( $options[ $value ] ).'" title="'.sprintf( esc_attr__( '%1$s on %2$s', 'attitude' ), get_bloginfo( 'name' ), $key ).'" target="_blank">'.get_bloginfo( 'name' ).$key.'</a></li>';
  340. }
  341. }
  342.  
  343. $attitude_socialnetworks .='
  344. </ul>
  345. </div><!-- .social-profiles -->';
  346.  
  347. set_transient( 'attitude_socialnetworks', $attitude_socialnetworks, 86940 );
  348. }
  349. echo $attitude_socialnetworks;
  350. }
  351. endif;
  352.  
  353. /****************************************************************************************/
  354.  
  355. if ( ! function_exists( 'attitude_home_slogan' ) ) :
  356. /**
  357. * Display Home Slogan.
  358. *
  359. * Function that enable/disable the home slogan1 and home slogan2.
  360. */
  361. function attitude_home_slogan() {
  362. global $attitude_theme_options_settings;
  363. $options = $attitude_theme_options_settings;
  364.  
  365. $attitude_home_slogan = '';
  366. if( ( !$attitude_home_slogan = get_transient( 'attitude_home_slogan' ) ) && ( !empty( $options[ 'home_slogan1' ] ) || !empty( $options[ 'home_slogan2' ] ) ) ) {
  367.  
  368. if ( "0" == $options[ 'disable_slogan' ] ) {
  369. $attitude_home_slogan .= '<section class="slogan-wrap clearfix"><div class="container"><div class="slogan">';
  370. if ( !empty( $options[ 'home_slogan1' ] ) ) {
  371. $attitude_home_slogan .= esc_html( $options[ 'home_slogan1' ] );
  372. }
  373. if ( !empty( $options[ 'home_slogan2' ] ) ) {
  374. $attitude_home_slogan .= '<span>'.esc_html( $options[ 'home_slogan2' ] ).'</span>';
  375. }
  376. $attitude_home_slogan .= '</div><!-- .slogan -->';
  377. if ( !empty( $options[ 'button_text' ] ) && !empty( $options[ 'redirect_button_link' ] ) ) {
  378. $attitude_home_slogan .= '<a class="view-work" href="'.esc_url( $options[ 'redirect_button_link' ] ).'" title="'.esc_attr( $options[ 'button_text' ] ).'">'.esc_html( $options[ 'button_text' ] ).'</a><!-- .view-work -->';
  379. }
  380. $attitude_home_slogan .= '</div><!-- .container --></section><!-- .slogan-wrap -->';
  381. }
  382.  
  383. set_transient( 'attitude_home_slogan', $attitude_home_slogan, 86940 );
  384. }
  385. echo $attitude_home_slogan;
  386. }
  387. endif;
  388.  
  389. /****************************************************************************************/
  390.  
  391. if ( ! function_exists( 'attitude_featured_post_slider' ) ) :
  392. /**
  393. * display featured post slider
  394. *
  395. * @uses set_transient and delete_transient
  396. */
  397. function attitude_featured_post_slider() {
  398. global $post;
  399.  
  400. global $attitude_theme_options_settings;
  401. $options = $attitude_theme_options_settings;
  402.  
  403. $attitude_featured_post_slider = '';
  404. if( ( !$attitude_featured_post_slider = get_transient( 'attitude_featured_post_slider' ) ) && !empty( $options[ 'featured_post_slider' ] ) ) {
  405.  
  406. if( 'wide-layout' == $options[ 'site_layout' ] ) {
  407. $slider_size = 'slider-wide';
  408. }
  409. else {
  410. $slider_size = 'slider-narrow';
  411. }
  412.  
  413. $attitude_featured_post_slider .= '
  414. <section class="featured-slider"><div class="slider-cycle">';
  415. $get_featured_posts = new WP_Query( array(
  416. 'posts_per_page' => $options[ 'slider_quantity' ],
  417. 'post_type' => array( 'post', 'page' ),
  418. 'post__in' => $options[ 'featured_post_slider' ],
  419. 'orderby' => 'post__in',
  420. 'ignore_sticky_posts' => 1 // ignore sticky posts
  421. ));
  422. $i=0; while ( $get_featured_posts->have_posts()) : $get_featured_posts->the_post(); $i++;
  423. $title_attribute = apply_filters( 'the_title', get_the_title( $post->ID ) );
  424. $excerpt = get_the_excerpt();
  425. if ( 1 == $i ) { $classes = "slides displayblock"; } else { $classes = "slides displaynone"; }
  426. $attitude_featured_post_slider .= '
  427. <div class="'.$classes.'">';
  428. if( has_post_thumbnail() ) {
  429.  
  430. $attitude_featured_post_slider .= '<figure>';
  431.  
  432. $attitude_featured_post_slider .= get_the_post_thumbnail( $post->ID, $slider_size, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ), 'class' => 'pngfix' ) ).'</figure>';
  433. }
  434. if( $title_attribute != '' || $excerpt !='' ) {
  435. $attitude_featured_post_slider .= '
  436. <article class="featured-text">';
  437. if( $title_attribute !='' ) {
  438. $attitude_featured_post_slider .= '<div class="featured-title">'. get_the_title() . '</div><!-- .featured-title -->';
  439. }
  440. if( $excerpt !='' ) {
  441. $attitude_featured_post_slider .= '<div class="featured-content">'.$excerpt.'</div><!-- .featured-content -->';
  442. }
  443. $attitude_featured_post_slider .= '
  444. </article><!-- .featured-text -->';
  445. }
  446. $attitude_featured_post_slider .= '
  447. </div><!-- .slides -->';
  448. endwhile; wp_reset_query();
  449. $attitude_featured_post_slider .= '</div>
  450. <nav id="controllers" class="clearfix">
  451. </nav><!-- #controllers --></section><!-- .featured-slider -->';
  452.  
  453. set_transient( 'attitude_featured_post_slider', $attitude_featured_post_slider, 86940 );
  454. }
  455. echo $attitude_featured_post_slider;
  456. }
  457. endif;
  458.  
  459. /****************************************************************************************/
  460.  
  461. if ( ! function_exists( 'attitude_breadcrumb' ) ) :
  462. /**
  463. * Display breadcrumb on header.
  464. *
  465. * If the page is home or front page, slider is displayed.
  466. * In other pages, breadcrumb will display if breadcrumb NavXT plugin exists.
  467. */
  468. function attitude_breadcrumb() {
  469. if( function_exists( 'bcn_display' ) ) {
  470. echo '<div class="breadcrumb">';
  471. bcn_display();
  472. echo '</div> <!-- .breadcrumb -->';
  473. }
  474. }
  475. endif;
  476.  
  477. /****************************************************************************************/
  478.  
  479. if ( ! function_exists( 'attitude_header_title' ) ) :
  480. /**
  481. * Show the title in header
  482. *
  483. * @since Attitude 1.0
  484. */
  485. function attitude_header_title() {
  486. if( is_archive() ) {
  487. $attitude_header_title = single_cat_title( '', FALSE );
  488. }
  489. elseif( is_404() ) {
  490. $attitude_header_title = __( 'Page NOT Found', 'attitude' );
  491. }
  492. elseif( is_search() ) {
  493. $attitude_header_title = __( 'Search Results', 'attitude' );
  494. }
  495. elseif( is_page_template() ) {
  496. $attitude_header_title = get_the_title();
  497. }
  498. else {
  499. $attitude_header_title = '';
  500. }
  501.  
  502. return $attitude_header_title;
  503.  
  504. }
  505. endif;
  506. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement