Want more features on Pastebin? Sign Up, it's FREE!
Guest

header-page

By: a guest on Sep 19th, 2012  |  syntax: None  |  size: 2.26 KB  |  views: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Page Header
  4.  * This is applied to pages (page.php) and those using page templates (tpl-*.php)
  5.  * It allows for use of the Page Header Override meta box option
  6.  * It makes $content title available to page templates
  7.  * $content_title has current page's title if no header image or if page override header image used and current page's title set to show beneath header
  8.  */
  9.  
  10. global $content_title; // make $content_title available to page templates
  11.  
  12. // Main header
  13. get_header();
  14.  
  15. // Title from this page
  16. $content_title = get_the_title( $post->ID );
  17.  
  18. // Header from another page (set with Page Header Override meta box)
  19. $header_override_page_id = get_post_meta( $post->ID, '_risen_page_header_page_id', true );
  20. $header_override_show_title = get_post_meta( $post->ID, '_risen_page_header_show_title', true );
  21. if ( ! empty( $header_override_page_id ) // page was set for override
  22.          && $header_override_page_id != $post->ID  // page chosen is not same as self
  23.          && has_post_thumbnail( $header_override_page_id ) // page has featured image
  24. ) {
  25.  
  26.         // Get override page data
  27.         $header_override_page = get_page( $header_override_page_id );
  28.        
  29.         // Change title and image to use those from override page
  30.         $header_title = $header_override_page->post_title;
  31.         $header_image = get_the_post_thumbnail( $header_override_page->ID, 'risen-header', array ( 'class' => 'page-header-image', 'title' => '' ) );
  32.        
  33.         // If this page's title not set to show below header override, blank it
  34.         if ( empty( $header_override_show_title ) ) {
  35.                 $content_title = '';
  36.         }
  37.        
  38. }
  39.  
  40. // Header from this page
  41. else {
  42.  
  43.         $header_title = $content_title;
  44.         $header_image = get_the_post_thumbnail( $post->ID, 'risen-header', array ( 'class' => 'page-header-image', 'title' => '' ) );
  45.  
  46.         // If has header image, do not repeat title beneath header
  47.         if ( $header_image ) {
  48.                 $content_title = '';
  49.         }
  50.        
  51. }
  52.  
  53. ?>
  54.  
  55. <?php if ( $header_image ) : // show title and breadcrumb path over header image if provided ?>
  56. <header id="page-header">
  57.         <?php echo $header_image; ?>
  58.         <?php if ( $header_title ) : ?>
  59.         <h1><?php echo $header_title; ?></h1>
  60.         <?php endif; ?>
  61.         <?php risen_breadcrumbs(); ?>
  62. </header>
  63. <?php else : // show breadcrumbs if no header image provided ?>
  64. <?php risen_breadcrumbs(); ?>
  65. <?php endif; ?>
clone this paste RAW Paste Data