Skip to content

Instantly share code, notes, and snippets.

@jamiemitchell
Forked from billerickson/functions.php
Created October 16, 2013 23:58
Show Gist options
  • Select an option

  • Save jamiemitchell/7017059 to your computer and use it in GitHub Desktop.

Select an option

Save jamiemitchell/7017059 to your computer and use it in GitHub Desktop.
<?php
/**
* Section Title
*
*/
function be_section_title() {
$section_info = array( 'title' => '', 'subtitle' => '', 'title_url' => '', 'subtitle_url' => '' );
// Blog
if( is_home() || is_single() || ( 'post' == get_post_type() && is_archive() ) ) {
$section_info['title'] = 'Blog';
$section_info['subtitle'] = 'Sharing WordPress tips and tricks as I find them';
}
if( is_single() || ( 'post' == get_post_type() && is_archive() ) )
$section_info['title_url'] = get_permalink( get_option( 'page_for_posts' ) );
// Portfolio
if( is_post_type_archive( 'projects' ) || is_tax( 'type' ) ) {
$section_info['title'] = 'Portfolio';
$section_info['subtitle'] = 'A selection of my recent work';
}
if( is_tax( 'type' ) ) {
$section_info['title_url'] = get_post_type_archive_link( 'projects' );
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ( $term->description )
$section_info['subtitle'] = $term->description;
}
// Code Snippets
if( is_singular( 'code' ) ) {
$section_info['title'] = 'Code Snippets';
$section_info['title_url'] = get_post_type_archive_link( 'code' );
}
// Filter
$section_info = apply_filters( 'be_section_info', $section_info );
// Display
if( empty( $section_info['title'] ) )
return;
$title = $subtitle = '';
$title = esc_attr( $section_info['title'] );
if( !empty( $section_info['title_url'] ) )
$title = '<a href="' . esc_url( $section_info['title_url'] ) . '">' . $title . '</a>';
if( !empty( $section_info['subtitle'] ) )
$subtitle = is_tax( 'type' ) ? $section_info['subtitle'] : esc_attr( $section_info['subtitle'] );
if( !empty( $section_info['subtitle_url'] ) )
$subtitle = '<a href="' . esc_url( $section_info['subtitle_url'] ) . '">' . $subtitle . '</a>';
if( !empty( $subtitle ) )
$subtitle = '<p class="subtitle">' . $subtitle . '</p>';
echo '<div id="section-title"><h1>' . $title . '</h1>' . $subtitle . '</div>';
}
add_action( 'genesis_before_content_sidebar_wrap', 'be_section_title' );
/**
* Page Section Info
*
* @param array $section_info
* @return array
*/
function be_page_section_info( $section_info ) {
if( !is_page() )
return $section_info;
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
$section_info['title'] = get_the_title();
global $post;
$alt_title = get_post_meta( $post->ID, 'be_section_title', true );
if ( !empty( $alt_title ) )
$section_info['title'] = $alt_title;
$subtitle = get_post_meta( $post->ID, 'be_section_subtitle', true );
if( !empty( $subtitle ) && !is_tax( 'type' ) )
$section_info['subtitle'] = $subtitle;
$title_url = get_post_meta( $post->ID, 'be_section_title_url', true );
if( ! empty( $title_url ) )
$section_info['title_url'] = $title_url;
$subtitle_url = get_post_meta ($post->ID, 'be_section_subtitle_url', true );
if( ! empty( $subtitle_url ) )
$section_info['subtitle_url'] = $subtitle_url;
return $section_info;
}
add_filter( 'be_section_info', 'be_page_section_info' );
<?php
/**
* Metaboxes
*
* This file registers any custom metaboxes
*
* @package BE_Genesis_Child
* @author Bill Erickson <bill@billerickson.net>
* @copyright Copyright (c) 2011, Bill Erickson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
function be_metabox( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'section-title',
'title' => 'Section Title',
'pages' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => 'Title',
'desc' => '',
'id' => 'be_section_title',
'type' => 'text',
),
array(
'name' => 'Title URL',
'desc' => '',
'id' => 'be_section_title_url',
'type' => 'text',
),
array(
'name' => 'Subtitle',
'desc' => '',
'id' => 'be_section_subtitle',
'type' => 'text',
),
array(
'name' => 'Subtitle URL',
'desc' => '',
'id' => 'be_section_subtitle_url',
'type' => 'text',
)
)
);
return $meta_boxes;
}
add_filter( 'cmb_meta_boxes' , 'be_metabox' );
/**
* Initialize Metabox Class
* see /lib/metabox/example-functions.php for more information
*
*/
function be_initialize_cmb_meta_boxes() {
if ( !class_exists( 'cmb_Meta_Box' ) ) {
require_once( BE_DIR . '/lib/metabox/init.php' );
}
}
add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment