'Topbar',
'header' => 'Header',
'footer' => 'Footer',
) );
}
}
add_action( 'after_setup_theme', 'alx_setup' );
/* Load custom widgets
/* ------------------------------------ */
if ( ! function_exists( 'alx_widgets' ) ) {
function alx_widgets()
{
load_template( get_template_directory() . '/functions/widgets/alx-tabs.php' );
load_template( get_template_directory() . '/functions/widgets/alx-video.php' );
load_template( get_template_directory() . '/functions/widgets/alx-posts.php' );
}
}
add_action( 'after_setup_theme', 'alx_widgets' );
/* Register sidebars
/* ------------------------------------ */
if ( ! function_exists( 'alx_sidebars' ) ) {
function alx_sidebars()
{
register_sidebar(array( 'name' => 'Primary','id' => 'primary','description' => "Normal full width sidebar", 'before_widget' => '
','after_widget' => '
','before_title' => '','after_title' => '
'));
register_sidebar(array( 'name' => 'Secondary','id' => 'secondary','description' => "Normal full width sidebar", 'before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
register_sidebar(array( 'name' => 'Footer 1','id' => 'footer-1', 'description' => "Widetized footer", 'before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
register_sidebar(array( 'name' => 'Footer 2','id' => 'footer-2', 'description' => "Widetized footer", 'before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
register_sidebar(array( 'name' => 'Footer 3','id' => 'footer-3', 'description' => "Widetized footer", 'before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
register_sidebar(array( 'name' => 'Footer 4','id' => 'footer-4', 'description' => "Widetized footer", 'before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
}
}
add_action( 'widgets_init', 'alx_sidebars' );
/* Enqueue javascript
/* ------------------------------------ */
if ( ! function_exists( 'alx_scripts' ) ) {
function alx_scripts()
{
wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/js/jquery.flexslider.min.js', array( 'jquery' ),'', false );
wp_enqueue_script( 'jplayer', get_template_directory_uri() . '/js/jquery.jplayer.min.js', array( 'jquery' ),'', true );
wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ),'', true );
if ( is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
}
}
add_action( 'wp_enqueue_scripts', 'alx_scripts' );
/* Enqueue css
/* ------------------------------------ */
if ( ! function_exists( 'alx_styles' ) ) {
function alx_styles()
{
wp_enqueue_style( 'style', get_stylesheet_uri() );
if ( !ot_get_option('responsive') ) { wp_enqueue_style( 'responsive', get_template_directory_uri().'/responsive.css' ); }
wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/fonts/font-awesome.min.css' );
}
}
add_action( 'wp_enqueue_scripts', 'alx_styles' );
/* ------------------------------------------------------------------------- *
* Template functions
/* ------------------------------------------------------------------------- */
/* Layout class
/* ------------------------------------ */
if ( ! function_exists( 'alx_layout_class' ) ) {
function alx_layout_class() {
// Default layout
$layout = 'col-3cm';
$default = 'col-3cm';
// Check for page/post specific layout
if ( is_page() || is_single() ) {
// Reset post data
wp_reset_postdata();
global $post;
// Get meta
$meta = get_post_meta($post->ID,'_layout',TRUE);
// Get if set and not set to inherit
if ( isset($meta) && !empty($meta) && $meta != 'inherit' ) { $layout = $meta; }
// Else check for page-global / single-global
elseif ( is_single() && ( ot_get_option('layout-single') !='inherit' ) ) $layout = ot_get_option('layout-single',''.$default.'');
elseif ( is_page() && ( ot_get_option('layout-page') !='inherit' ) ) $layout = ot_get_option('layout-page',''.$default.'');
// Else get global option
else $layout = ot_get_option('layout-global',''.$default.'');
}
// Set layout based on page
elseif ( is_home() && ( ot_get_option('layout-home') !='inherit' ) ) $layout = ot_get_option('layout-home',''.$default.'');
elseif ( is_category() && ( ot_get_option('layout-archive-category') !='inherit' ) ) $layout = ot_get_option('layout-archive-category',''.$default.'');
elseif ( is_archive() && ( ot_get_option('layout-archive') !='inherit' ) ) $layout = ot_get_option('layout-archive',''.$default.'');
elseif ( is_search() && ( ot_get_option('layout-search') !='inherit' ) ) $layout = ot_get_option('layout-search',''.$default.'');
elseif ( is_404() && ( ot_get_option('layout-404') !='inherit' ) ) $layout = ot_get_option('layout-404',''.$default.'');
// Global option
else $layout = ot_get_option('layout-global',''.$default.'');
// Return layout
return $layout;
}
}
/* Dual sidebars? Get sidebar-2 template
/* ------------------------------------ */
if ( ! function_exists( 'alx_sidebar_dual' ) ) {
function alx_sidebar_dual() {
global $post;
if (
( is_home() && (
( ot_get_option('layout-home') =='col-3cm' ) ||
( ot_get_option('layout-home') =='col-3cl' ) ||
( ot_get_option('layout-home') =='col-3cr' ) )
) ||
( is_single() && (
( ot_get_option('layout-single') =='col-3cm' ) ||
( ot_get_option('layout-single') =='col-3cl' ) ||
( ot_get_option('layout-single') =='col-3cr' ) )
) ||
( is_archive() && (
( ot_get_option('layout-archive') =='col-3cm' ) ||
( ot_get_option('layout-archive') =='col-3cl' ) ||
( ot_get_option('layout-archive') =='col-3cr' ) )
) ||
( is_category() && (
( ot_get_option('layout-archive-category') =='col-3cm' ) ||
( ot_get_option('layout-archive-category') =='col-3cl' ) ||
( ot_get_option('layout-archive-category') =='col-3cr' ) )
) ||
( is_search() && (
( ot_get_option('layout-search') =='col-3cm' ) ||
( ot_get_option('layout-search') =='col-3cl' ) ||
( ot_get_option('layout-search') =='col-3cr' ) )
) ||
( is_404() && (
( ot_get_option('layout-404') =='col-3cm' ) ||
( ot_get_option('layout-404') =='col-3cl' ) ||
( ot_get_option('layout-404') =='col-3cr' ) )
) ||
( is_page() && (
( ot_get_option('layout-page') =='col-3cm' ) ||
( ot_get_option('layout-page') =='col-3cl' ) ||
( ot_get_option('layout-page') =='col-3cr' ) )
)
)
{ get_template_part('sidebar-2'); }
elseif (
( is_page() || is_single() ) && (
( get_post_meta($post->ID,'_layout',true) == 'col-3cm' ) ||
( get_post_meta($post->ID,'_layout',true) == 'col-3cl' ) ||
( get_post_meta($post->ID,'_layout',true) == 'col-3cr' ) )
)
{ get_template_part('sidebar-2'); }
elseif (
( ot_get_option('layout-global') =='col-3cm' ) ||
( ot_get_option('layout-global') =='col-3cl' ) ||
( ot_get_option('layout-global') =='col-3cr' )
)
{ get_template_part('sidebar-2'); }
}
}
/* Dynamic sidebar primary
/* ------------------------------------ */
if ( ! function_exists( 'alx_sidebar_primary' ) ) {
function alx_sidebar_primary() {
// Default sidebar
$sidebar = 'primary';
// Set sidebar based on page
if ( is_home() && ot_get_option('s1-home') ) $sidebar = ot_get_option('s1-home');
if ( is_single() && ot_get_option('s1-single') ) $sidebar = ot_get_option('s1-single');
if ( is_archive() && ot_get_option('s1-archive') ) $sidebar = ot_get_option('s1-archive');
if ( is_category() && ot_get_option('s1-archive-category') ) $sidebar = ot_get_option('s1-archive-category');
if ( is_search() && ot_get_option('s1-search') ) $sidebar = ot_get_option('s1-search');
if ( is_404() && ot_get_option('s1-404') ) $sidebar = ot_get_option('s1-404');
if ( is_page() && ot_get_option('s1-page') ) $sidebar = ot_get_option('s1-page');
// Check for page/post specific sidebar
if ( is_page() || is_single() ) {
// Reset post data
wp_reset_postdata();
global $post;
// Get meta
$meta = get_post_meta($post->ID,'_sidebar_primary',true);
if ( $meta ) { $sidebar = $meta; }
}
// Return sidebar
return $sidebar;
}
}
/* Dynamic sidebar secondary
/* ------------------------------------ */
if ( ! function_exists( 'alx_sidebar_secondary' ) ) {
function alx_sidebar_secondary() {
// Default sidebar
$sidebar = 'secondary';
// Set sidebar based on page
if ( is_home() && ot_get_option('s2-home') ) $sidebar = ot_get_option('s2-home');
if ( is_single() && ot_get_option('s2-single') ) $sidebar = ot_get_option('s2-single');
if ( is_archive() && ot_get_option('s2-archive') ) $sidebar = ot_get_option('s2-archive');
if ( is_category() && ot_get_option('s2-archive-category') ) $sidebar = ot_get_option('s2-archive-category');
if ( is_search() && ot_get_option('s2-search') ) $sidebar = ot_get_option('s2-search');
if ( is_404() && ot_get_option('s2-404') ) $sidebar = ot_get_option('s2-404');
if ( is_page() && ot_get_option('s2-page') ) $sidebar = ot_get_option('s2-page');
// Check for page/post specific sidebar
if ( is_page() || is_single() ) {
// Reset post data
wp_reset_postdata();
global $post;
// Get meta
$meta = get_post_meta($post->ID,'_sidebar_secondary',true);
if ( $meta ) { $sidebar = $meta; }
}
// Return sidebar
return $sidebar;
}
}
/* Social links
/* ------------------------------------ */
if ( ! function_exists( 'alx_social_links' ) ) {
function alx_social_links() {
if ( !ot_get_option('social-links') =='' ) {
$links = ot_get_option('social-links', array());
if ( !empty( $links ) ) {
echo '';
foreach( $links as $item ) {
// Build each separate html-section only if set
if ( isset($item['title']) && !empty($item['title']) )
{ $title = 'title="' .$item['title']. '"'; } else $title = '';
if ( isset($item['social-link']) && !empty($item['social-link']) )
{ $link = 'href="' .$item['social-link']. '"'; } else $link = '';
if ( isset($item['social-target']) && !empty($item['social-target']) )
{ $target = 'target="' .$item['social-target']. '"'; } else $target = '';
if ( isset($item['social-icon']) && !empty($item['social-icon']) )
{ $icon = 'class="fa ' .$item['social-icon']. '"'; } else $icon = '';
if ( isset($item['social-color']) && !empty($item['social-color']) )
{ $color = 'style="color: ' .$item['social-color']. ';"'; } else $color = '';
// Put them together
if ( isset($item['title']) && !empty($item['title']) && isset($item['social-icon']) && !empty($item['social-icon']) && ($item['social-icon'] !='fa-') ) {
echo ' ';
}
}
echo '
';
}
}
}
}
/* Site name/logo
/* ------------------------------------ */
if ( ! function_exists( 'alx_site_title' ) ) {
function alx_site_title() {
// Text or image?
if ( ot_get_option('custom-logo') ) {
$logo = '';
} else {
$logo = get_bloginfo('name');
}
$link = ''.$logo.'';
if ( is_front_page() || is_home() ) {
$sitename = ''.$link.'
'."\n";
} else {
$sitename = ''.$link.'
'."\n";
}
return $sitename;
}
}
/* Page title
/* ------------------------------------ */
if ( ! function_exists( 'alx_page_title' ) ) {
function alx_page_title() {
global $post;
$heading = get_post_meta($post->ID,'_heading',TRUE);
$subheading = get_post_meta($post->ID,'_subheading',TRUE);
$title = $heading?$heading:the_title();
if($subheading) {
$title = $title.' '.$subheading.'';
}
return $title;
}
}
/* Blog title
/* ------------------------------------ */
if ( ! function_exists( 'alx_blog_title' ) ) {
function alx_blog_title() {
global $post;
$heading = ot_get_option('blog-heading');
$subheading = ot_get_option('blog-subheading');
if($heading) {
$title = $heading;
} else {
$title = get_bloginfo('name');
}
if($subheading) {
$title = $title.' '.$subheading.'';
}
return $title;
}
}
/* Related posts
/* ------------------------------------ */
if ( ! function_exists( 'alx_related_posts' ) ) {
function alx_related_posts() {
wp_reset_postdata();
global $post;
// Define shared post arguments
$args = array(
'no_found_rows' => TRUE,
'update_post_meta_cache' => FALSE,
'update_post_term_cache' => FALSE,
'ignore_sticky_posts' => 1,
'orderby' => 'rand',
'post__not_in' => array($post->ID),
'posts_per_page' => 3
);
// Related by categories
if ( ot_get_option('related-posts') == 'categories' ) {
$cats = get_post_meta($post->ID, 'related-cat', TRUE);
if ( !$cats ) {
$cats = wp_get_post_categories($post->ID, array('fields'=>'ids'));
$args['category__in'] = $cats;
} else {
$args['cat'] = $cats;
}
}
// Related by tags
if ( ot_get_option('related-posts') == 'tags' ) {
$tags = get_post_meta($post->ID, 'related-tag', TRUE);
if ( !$tags ) {
$tags = wp_get_post_tags($post->ID, array('fields'=>'ids'));
$args['tag__in'] = $tags;
} else {
$args['tag_slug__in'] = explode(',', $tags);
}
if ( !$tags ) { $break = TRUE; }
}
$query = !isset($break)?new WP_Query($args):new WP_Query;
return $query;
}
}
/* Get images attached to post
/* ------------------------------------ */
if ( ! function_exists( 'alx_post_images' ) ) {
function alx_post_images( $args=array() ) {
global $post;
$defaults = array(
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'menu_order',
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_type' => 'attachment',
);
$args = wp_parse_args( $args, $defaults );
return get_posts( $args );
}
}
/* ------------------------------------------------------------------------- *
* Admin panel functions
/* ------------------------------------------------------------------------- */
/* Custom sidebars
/* ------------------------------------ */
if ( ! function_exists( 'alx_custom_sidebars' ) ) {
function alx_custom_sidebars() {
if ( !ot_get_option('sidebar-areas') =='' ) {
$sidebars = ot_get_option('sidebar-areas', array());
if ( !empty( $sidebars ) ) {
foreach( $sidebars as $sidebar ) {
if ( isset($sidebar['title']) && !empty($sidebar['title']) && isset($sidebar['id']) && !empty($sidebar['id']) && ($sidebar['id'] !='sidebar-') ) {
register_sidebar(array('name' => ''.$sidebar['title'].'','id' => ''.$sidebar['id'].'','before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
}
}
}
}
}
}
add_action( 'widgets_init', 'alx_custom_sidebars' );
/* Get featured post ids
/* ------------------------------------ */
if ( ! function_exists( 'alx_get_featured_post_ids' ) ) {
function alx_get_featured_post_ids() {
$args = array(
'category' => ot_get_option('featured-category'),
'numberposts' => ot_get_option('featured-posts-count')
);
$posts = get_posts($args);
if ( !$posts ) return FALSE;
foreach ( $posts as $post )
$ids[] = $post->ID;
return $ids;
}
}
/* Post formats script
/* ------------------------------------ */
if ( ! function_exists( 'alx_post_formats_script' ) ) {
function alx_post_formats_script( $hook ) {
// Only load on posts, pages
if ( !in_array($hook, array('post.php','post-new.php')) )
return;
wp_enqueue_script('post-formats', get_template_directory_uri() . '/functions/js/post-formats.js', array( 'jquery' ));
}
}
add_action( 'admin_enqueue_scripts', 'alx_post_formats_script');
/* ------------------------------------------------------------------------- *
* Filters
/* ------------------------------------------------------------------------- */
/* Site title
/* ------------------------------------ */
if ( ! function_exists( 'alx_wp_title' ) ) {
function alx_wp_title( $title ) {
// Do not filter for RSS feed / if SEO plugin installed
if ( is_feed() || class_exists('All_in_One_SEO_Pack') )
return $title;
if ( is_front_page() ) {
$title = bloginfo('name'); echo ' - '; bloginfo('description');
}
if ( !is_front_page() ) {
$title.= ''.' - '.''.get_bloginfo('name');
}
return $title;
}
}
add_filter( 'wp_title', 'alx_wp_title' );
/* Custom rss feed
/* ------------------------------------ */
if ( ! function_exists( 'alx_feed_link' ) ) {
function alx_feed_link( $output, $feed ) {
// Do not redirect comments feed
if ( strpos( $output, 'comments' ) )
return $output;
// Return feed url
return ot_get_option('rss-feed',$output);
}
}
add_filter( 'feed_link', 'alx_feed_link', 10, 2 );
/* Custom favicon
/* ------------------------------------ */
if ( ! function_exists( 'alx_favicon' ) ) {
function alx_favicon() {
if ( ot_get_option('favicon') ) {
echo ''."\n";
}
}
}
add_filter( 'wp_head', 'alx_favicon' );
/* Body class
/* ------------------------------------ */
if ( ! function_exists( 'alx_body_class' ) ) {
function alx_body_class( $classes ) {
if ( has_nav_menu('topbar') ) { $classes[] = 'topbar-enabled'; }
if ( !ot_get_option( 'boxed' ) ) { $classes[] = 'full-width'; }
if ( ot_get_option( 'boxed' ) ) { $classes[] = 'boxed'; }
if ( ot_get_option( 'mobile-sidebar-hide' ) == 's1' ) { $classes[] = 'mobile-sidebar-hide-s1'; }
if ( ot_get_option( 'mobile-sidebar-hide' ) == 's2' ) { $classes[] = 'mobile-sidebar-hide-s2'; }
if ( ot_get_option( 'mobile-sidebar-hide' ) == 's1-s2' ) { $classes[] = 'mobile-sidebar-hide'; }
return $classes;
}
}
add_filter( 'body_class', 'alx_body_class' );
/* Excerpt ending
/* ------------------------------------ */
if ( ! function_exists( 'alx_excerpt_more' ) ) {
function alx_excerpt_more( $more ) {
return '...';
}
}
add_filter( 'excerpt_more', 'alx_excerpt_more' );
/* Excerpt length
/* ------------------------------------ */
if ( ! function_exists( 'alx_excerpt_length' ) ) {
function alx_excerpt_length( $length ) {
return ot_get_option('excerpt-length',$length);
}
}
add_filter( 'excerpt_length', 'alx_excerpt_length', 999 );
/* Add wmode transparent to media embeds
/* ------------------------------------ */
if ( ! function_exists( 'alx_embed_wmode_transparent' ) ) {
function alx_embed_wmode_transparent( $html, $url, $attr ) {
if ( strpos( $html, "