Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
853 lines (769 sloc) 32.9 KB
<?php
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CLAS
February 2014
by UITS Web Lab brian.dunnigan@uconn.edu
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">Read More</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
function custom_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
add_theme_support( 'post-thumbnails' );
// If no Menu is created, displays a home link, and starts listing pages across the top.
function huskypress_page_menu_args( $args ) {
if ( ! isset( $args['show_home'] ) )
$args['show_home'] = true;
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'huskypress_page_menu_args' );
// register the menus
function register_my_menus() {
register_nav_menu( 'primary', __( 'Primary Menu', 'clas' ) );
}
add_action( 'init', 'register_my_menus' );
add_action( 'init', 'create_post_type' );
function create_post_type() {
$labels = array(
'name' => _x( 'New Faculty', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'New Faculty', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'New Faculty', 'text_domain' ),
'parent_item_colon' => __( 'Parent New Faculty:', 'text_domain' ),
'all_items' => __( 'All New Faculty', 'text_domain' ),
'view_item' => __( 'View New Faculty', 'text_domain' ),
'add_new_item' => __( 'Add New Faculty', 'text_domain' ),
'add_new' => __( 'New Faculty', 'text_domain' ),
'edit_item' => __( 'Edit New Faculty', 'text_domain' ),
'update_item' => __( 'Update New Faculty', 'text_domain' ),
'search_items' => __( 'Search New Faculty', 'text_domain' ),
'not_found' => __( 'No New Faculty found', 'text_domain' ),
'not_found_in_trash' => __( 'No New Faculty found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'New Faculty', 'text_domain' ),
'description' => __( 'New Faculty', 'text_domain' ),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'post-formats', 'categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-groups',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'new_faculty',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => true
);
register_post_type( 'new_faculty', $args );
$labels = array(
'name' => _x( 'Dean\'s Office Staff', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Dean\'s Office Staff', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Dean\'s Office Staff', 'text_domain' ),
'parent_item_colon' => __( 'Parent Dean\'s Office Staff:', 'text_domain' ),
'all_items' => __( 'All Dean\'s Office Staff', 'text_domain' ),
'view_item' => __( 'View Dean\'s Office Staff', 'text_domain' ),
'add_new_item' => __( 'Add Dean\'s Office Staff', 'text_domain' ),
'add_new' => __( 'New Dean\'s Office Staff', 'text_domain' ),
'edit_item' => __( 'Edit Dean\'s Office Staff', 'text_domain' ),
'update_item' => __( 'Update Dean\'s Office Staff', 'text_domain' ),
'search_items' => __( 'Search Dean\'s Office Staff', 'text_domain' ),
'not_found' => __( 'No Dean\'s Office Staff found', 'text_domain' ),
'not_found_in_trash' => __( 'No Dean\'s Office Staff found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'Dean\'s Office Staff', 'text_domain' ),
'description' => __( 'Dean\'s Office Staff', 'text_domain' ),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'post-formats', 'categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-groups',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'deans_office_staff',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => true
);
register_post_type( 'deans_office_staff', $args );
$labels = array(
'name' => _x( 'Endowed Chairs', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Endowed Chairs', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Endowed Chairs', 'text_domain' ),
'parent_item_colon' => __( 'Parent Endowed Chairs:', 'text_domain' ),
'all_items' => __( 'All Endowed Chairs', 'text_domain' ),
'view_item' => __( 'View Endowed Chairs', 'text_domain' ),
'add_new_item' => __( 'Add Endowed Chairs', 'text_domain' ),
'add_new' => __( 'New Endowed Chairs', 'text_domain' ),
'edit_item' => __( 'Edit Endowed Chairs', 'text_domain' ),
'update_item' => __( 'Update Endowed Chairs', 'text_domain' ),
'search_items' => __( 'Search Endowed Chairs', 'text_domain' ),
'not_found' => __( 'No Endowed Chairs found', 'text_domain' ),
'not_found_in_trash' => __( 'No Endowed Chairs found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'Endowed Chairs', 'text_domain' ),
'description' => __( 'Endowed Chairs', 'text_domain' ),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'post-formats', 'categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-groups',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'endowed_chairs',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => true
);
register_post_type( 'endowed_chairs', $args );
$labels = array(
'name' => _x( 'Extra Template', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Extra Template', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Extra Template', 'text_domain' ),
'parent_item_colon' => __( 'Parent Extra Template:', 'text_domain' ),
'all_items' => __( 'All Extra Template', 'text_domain' ),
'view_item' => __( 'View Extra Template', 'text_domain' ),
'add_new_item' => __( 'Add Extra Template', 'text_domain' ),
'add_new' => __( 'New Extra Template', 'text_domain' ),
'edit_item' => __( 'Edit Extra Template', 'text_domain' ),
'update_item' => __( 'Update Extra Template', 'text_domain' ),
'search_items' => __( 'Search Extra Template', 'text_domain' ),
'not_found' => __( 'No Extra Template found', 'text_domain' ),
'not_found_in_trash' => __( 'No Extra Template found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'Extra Template', 'text_domain' ),
'description' => __( 'Extra Template', 'text_domain' ),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'post-formats', 'categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-groups',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'extra_template',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => true
);
register_post_type( 'extra_template', $args );
}
/**
* Hooks the WP cpt_post_types filter
*
* @param array $post_types An array of post type names that the templates be used by
* @return array The array of post type names that the templates be used by
**/
function my_cpt_post_types( $post_types ) {
$post_types[] = 'new_faculty';
$post_types[] = 'deans_office_staff';
$post_types[] = 'endowed_chairs';
$post_types[] = 'extra_template';
return $post_types;
}
add_filter( 'cpt_post_types', 'my_cpt_post_types' );
/*
Disabled until theme supports these types... (AB June 26, 2013)
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
*/
$header_args = array(
'width' => 950,
'header-text' => false,
'default-image' => get_template_directory_uri() . '/images/header.jpg',
);
add_theme_support( 'custom-header', $header_args );
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home1',
'id' => 'home1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home2',
'id' => 'home2',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home - 3rd Row - Left',
'id' => 'home3-ll',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home - 3rd Row - Center',
'id' => 'home3-lc',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home - 3rd Row - Right',
'id' => 'home3-lr',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Single Story Sidebar',
'id' => 'single-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
}
// If no Menu is created, displays a home link, and starts listing pages across the top.
function hale_page_menu_args( $args ) {
if ( ! isset( $args['show_home'] ) )
$args['show_home'] = true;
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'hale_page_menu_args' );
function hale_enqueue_scripts() {
wp_enqueue_script('bootstrap-min', get_bloginfo('template_url').'/bootstrap/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('uc-modernizr', get_bloginfo('template_url').'/js/uc-modernizr.js', array('jquery'));
wp_enqueue_script('uc-hale-custom', get_bloginfo('template_url').'/js/custom.js', array('jquery'));
wp_enqueue_script('uc-custom-dean', get_bloginfo('template_url').'/js/custom-deans.js', array('jquery'));
$data = array('site_url' => __(site_url()));
wp_enqueue_script('history', get_bloginfo('template_url').'/js/jquery.history.js', array('jquery'));//Used for News-Archive page
wp_localize_script( 'uc-hale-custom', 'clas_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'siteurl' => site_url() ) );
}
add_action('wp_enqueue_scripts', 'hale_enqueue_scripts');
function clas_slider_enqueue_scripts() {
wp_enqueue_script('uc-hale-custom-slider', get_bloginfo('template_url').'/js/custom-slider.js', array('jquery'), false, true);
}
add_action('wp_enqueue_scripts', 'clas_slider_enqueue_scripts');
add_action( 'wp_ajax_clas_post_content', 'ajax_clas_post_content' );
add_action('wp_ajax_nopriv_clas_post_content', 'ajax_clas_post_content');
function ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive
$id = $_POST['postID'];
global $post;
$content_post = get_post($id);
$post = $content_post;
//$content = do_shortcode(wpautop($content_post->post_content));
$content = apply_filters('the_content', $content_post->post_content );
$title = $content_post->post_title;
$date = get_the_time( 'F j, Y', $id );
$featured_image = get_the_post_thumbnail( $id, 'medium' );
$link = get_permalink( $id );
$slug = $content_post->post_name;
$object = new stdClass();
$object->content = htmlspecialchars_decode($content);
$object->title = $title;
$object->postdate = $date;
$object->image = $featured_image;
$object->link = $link;
$object->slug = $slug;
$object->id = $id;
echo wp_json_encode($object);
die();
}
function getPostExcerpt( $id ){
$content = get_post($id)->post_content;
$excerpt = strip_tags( strip_shortcodes( $content ) );
$words = explode(' ', $excerpt, 201);
if(count($words) > 200){
array_pop($words);
array_push($words, '');
$excerpt = implode(' ', $words);
}
$excerpt = '<p>'.$excerpt.'</p>';
return $excerpt;
}
function getPostSlug( $id ){
return get_post($id)->post_name;
}
add_action( 'wp_ajax_clas_posts', 'ajax_clas_posts' );
add_action('wp_ajax_nopriv_clas_posts', 'ajax_clas_posts');
function ajax_clas_posts(){
$posts = $_POST['postIDs'];
$postObj = new stdClass();
if( !empty($posts) ){
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->excerpt = getPostExcerpt($id);
$postObj->$k->date = get_the_time('F j, Y', $id);
$postObj->$k->featuredImage = get_the_post_thumbnail($id, 'medium', $attr);
}
$json = wp_json_encode( $postObj );
}
echo $json;
wp_die();
}
add_action( 'wp_ajax_clas_tag_posts', 'ajax_clas_tag_posts' );
add_action('wp_ajax_nopriv_clas_tag_posts', 'ajax_clas_tag_posts');
function ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name
$tag = $_POST['tag'];
$args = array(
'numberposts' => -1,
'fields' => 'ids'
);
if( $tag !== 'all-divisions' ){
$args['tag'] = $tag;
}
$posts = get_posts( $args );
if( !empty($posts) ){
$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
$json = wp_json_encode( $postObj );
}
echo $json;
wp_die();
}
add_action( 'wp_ajax_clas_cat_posts', 'ajax_clas_cat_posts' );
add_action('wp_ajax_nopriv_clas_cat_posts', 'ajax_clas_cat_posts');
function ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id
$tax = $_POST['taxonomy'];
$val = $_POST['value'];
$args = array(
'field' => 'ids',
'numberposts' => -1
);
if( $tax == 'category' ){
$args['cat'] = $val;
//$taxName = get_cat_name($val);
} else if( $tax == 'tag' ) {
$args['tag_id'] = $val;
//$taxName = get_tag($val)->name;
}
$posts = get_posts( $args );
$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id->ID;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
echo wp_json_encode($postObj);
wp_die();
}
add_action( 'wp_ajax_clas_search_archive', 'ajax_clas_search_archive' );
add_action('wp_ajax_nopriv_clas_search_archive', 'ajax_clas_search_archive');
function ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id
$search = $_POST['search'];
$args = array(
's' => $search,
'fields' => 'ids',
'category_name' => 'archive'
);
$archiveQuery = new WP_Query( $args );
$archivePosts = $archiveQuery->get_posts();
$postObj = new stdClass();
foreach( $archivePosts as $k=>$id ){
if( in_array($id, $archivePosts) ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
}
echo wp_json_encode( $postObj );
wp_die();
}
add_action( 'wp_ajax_clas_orderby_posts', 'ajax_clas_orderby_posts' );
add_action('wp_ajax_nopriv_clas_orderby_posts', 'ajax_clas_orderby_posts');
function ajax_clas_orderby_posts() { //Retrieves and sorts posts by date
$info = $_POST['info'];
$order = $info['order'];
$ids = $info['posts'];
$args = array(
'include' => $ids,
'order'=> $order,
'field' => 'ids',
'numberposts' => -1
);
$posts = get_posts( $args );
$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id->ID;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
echo wp_json_encode($postObj);
wp_die();
}
add_action( 'wp_ajax_clas_taxid', 'ajax_clas_taxid' );
add_action('wp_ajax_nopriv_clas_taxid', 'ajax_clas_taxid');
function ajax_clas_taxid(){
$taxonomyName = $_POST['taxonomyName'];
$taxonomyType = $_POST['taxonomyType'];
if( $taxonomyType == 'category' ){
$idObj = get_category_by_slug($taxonomyName);
$id = $idObj->term_id;
} else if( $taxonomyType == 'tag' ) {
$idObj = get_term_by('slug', $taxonomyName, 'post_tag');
$id = $idObj->term_id;
}
echo wp_json_encode( $id );
wp_die();
}
function huskypress_customize_register( $wp_customize )
{
//1. Define a new section (if desired) to the Theme Customizer
$wp_customize->add_section( 'huskypress_options',
array(
'title' => __( 'Template Options', 'mytheme' ), //Visible title of section
'priority' => 35, //Determines what order this appears in
'capability' => 'edit_theme_options', //Capability needed to tweak
'description' => __('Allows you to customize header color and school, college, or division settings for Hale', 'huskypress'), //Descriptive tooltip
)
);
$wp_customize->add_setting( 'templatecolor', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => 'blue', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('templatecolor', array(
'type' => 'radio',
'label' => 'UConn Header Color',
'section' => 'huskypress_options',
'choices' => array(
'blue'=>'Blue'/*,
'white'=>'White',
'gray'=>'Gray'*/
)
)
);
$wp_customize->add_setting( 'templatelocation', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => 'uconn', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('templatelocation', array(
'type' => 'radio',
'label' => 'UConn Header Logo',
'section' => 'huskypress_options',
'choices' => array(
'uconn'=>'University of Connecticut',
'uchc'=>'UConn Health Center'
)
)
);
$wp_customize->add_setting( 'secondarytitle', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => '-- Choose One --', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$secondaries = array("-- Choose One --"=>"choose",
"Center for Continuing Studies"=>"http://continuingstudies.uconn.edu/",
"College of Agriculture and Natural Resources"=>"http://www.cag.uconn.edu/CANR/index.html",
"College of Liberal Arts and Sciences"=>"http://www.clas.uconn.edu/",
"Division of Athletics"=>"http://www.uconnhuskies.com/",
"Division of Enrollment Management"=>"",
"Division of Public Safety"=>"http://web.uconn.edu/publicsafety/",
"Division of Student Affairs"=>"http://www.studentaffairs.uconn.edu/",
"Division of Undergraduate Education and Instruction"=>"http://vped.uconn.edu/",
"Graduate School"=>"http://grad.uconn.edu/",
"Neag School of Education"=>"http://www.education.uconn.edu/",
"Ratcliffe Hicks School of Agriculture"=>"http://www.cag.uconn.edu/rh/rh/",
"School of Business"=>"http://www.business.uconn.edu/cms/",
"School of Dental Medicine"=>"http://sdm.uchc.edu/",
"School of Engineering"=>"http://www.engr.uconn.edu/",
"School of Fine Arts"=>"http://www.sfa.uconn.edu/",
"School of Law"=>"http://www.law.uconn.edu/",
"School of Medicine"=>"http://medicine.uchc.edu/",
"School of Nursing"=>"http://www.nursing.uconn.edu/index.php",
"School of Pharmacy"=>"http://pharmacy.uconn.edu/",
"School of Social Work"=>"http://www.ssw.uconn.edu/",
"Transportation, Logistics and Parking Services"=>"http://park.uconn.edu/",
"University Information Technology Services"=>"http://uits.uconn.edu/",
"University Libraries"=>"http://www.lib.uconn.edu/",
"Carole and Ray Neag Comprehensive Cancer Center" => "http://cancer.uchc.edu/",
"New England Musculoskeletal Institute" => "http://nemsi.uchc.edu/",
"Pat and Jim Calhoun Cardiology Center" => "http://heart.uchc.edu/");
$secondarytitles = array();
foreach($secondaries as $secondary=>$url){
$secondarytitles[$secondary] = $secondary;
}
$wp_customize->add_control('secondarytitle', array(
'type' => 'select',
'label' => 'School, College, or Division',
'section' => 'huskypress_options',
'choices' => $secondarytitles
)
);
$wp_customize->add_setting( 'homepagelayout', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => '3-3', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('homepagelayout', array(
'type' => 'radio',
'label' => 'Homepage Layout',
'section' => 'huskypress_options',
'choices' => array(
'1-3'=>'1-3',
'2L-3'=>'2L-3',
'2R-3'=>'2R-3',
'3-3'=>'3-3',
'3-4'=>'3-4'
)
)
);
}
add_action( 'customize_register', 'huskypress_customize_register' );
/*the fallback from wp_nav_menu, we want to replicate the output of wp_page_menu to be similar to wp_nav_menu
@param args, it comes from the wp_nav_menu arguments*/
function hale_main_nav_fallback($args) {
$args['echo'] = 0; // don't echo the output yet.
$nav_menu = wp_page_menu($args);
if(!empty($nav_menu)){
$doc = new DOMDocument();
@$doc->loadHTML($nav_menu);//surpress the warnings
$data = $doc->getElementsByTagName('li');
//the default behaviour of wp_page_menu is that it wraps the list items with a ul and div
//menu_class is for div in wp_page_menu, but is for the ul in wp_nav_menu
//create the container, if any
//container class and id come from wp_nav_menu arguments. Which is not used in wp_page_menu.
if($args['container'] != false) {
$attributes = (!empty($args['container_class'])?' class="'.$args['container_class'].'"':'');
$attributes .= (!empty($args['container_id'])?' id="'.$args['container_id'].'"':'');
if($args['container'] == 'nav') {
echo '<nav'.$attributes.'>';
} else {
echo '<div'.$attributes.'>';
}
}
$attributes = (!empty($args['menu_class'])?' class="'.$args['menu_class'].'"':'');
$attributes .= (!empty($args['menu_id'])?' id="'.$args['menu_id'].'"':'');
echo '<ul'.$attributes.'>';
if($data->length > 0) {
foreach($data as $item) {
echo $item->ownerDocument->saveXML($item);//saveHTML wouldn't accept it as paramater.
}
}
echo '</ul>';
//close the container, if any
if($args['container'] != false) {
if($args['container'] == 'nav') {
echo '</nav>';
} else {
echo '</div>';
}
}
}
return;
}
/*Nav Menu Walker*/
if(!class_exists('Bootstrap_Nav_Walker')) {
class Bootstrap_Nav_Walker extends Walker_Nav_Menu {
/*This was taken from 320press WP-Bootstrap theme. No licensing restriction given, and it said it was free. */
/* Start of the <ul>
*
* Note on $depth: Counterintuitively, $depth here means the "depth right before we start this menu".
* So basically add one to what you'd expect it to be
*/
function start_lvl(&$output, $depth, $args)
{
if(isset($args->with_search) && $args->with_search == true){
add_filter('wp_nav_menu_items', 'search_menu_item', 1, 2);
}
$tabs = str_repeat("\t", $depth);
// If we are about to start the first submenu, we need to give it a dropdown-menu class
if ($depth >= 0) { //really, level-1 or level-2, because $depth is misleading here (see note above)
$output .= "\n{$tabs}<ul class=\"dropdown-menu\">\n";
} else {
$output .= "\n{$tabs}<ul>\n";
}
return;
}
/* End of the <ul>
*
* Note on $depth: Counterintuitively, $depth here means the "depth right before we start this menu".
* So basically add one to what you'd expect it to be
*/
function end_lvl(&$output, $depth)
{
if ($depth == 0) { // This is actually the end of the level-1 submenu ($depth is misleading here too!)
// we don't have anything special for Bootstrap, so we'll just leave an HTML comment for now
$output .= '<!--.dropdown-->';
}
$tabs = str_repeat("\t", $depth);
$output .= "\n{$tabs}</ul>\n";
return;
}
/* Output the <li> and the containing <a>
* Note: $depth is "correct" at this level
*/
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
/* If this item has a dropdown menu, add the 'dropdown' class for Bootstrap */
if($item->post_type == 'page') { //page has no classes..
$classes[] = 'menu-item';
}
if ($item->hasChildren) {
$classes[] = 'dropdown';
// level-1 menus also need the 'dropdown-submenu' class
if($depth > 0 ) {
$classes[] = 'dropdown-submenu';
}
}
/* This is the stock Wordpress code that builds the <li> with all of its attributes */
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
if($item->post_type == 'page') {
$attributes .= ! empty( $item->guid ) ? ' href="' . esc_attr( $item->guid ) .'"' : '';
} else {
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
}
$item_output = "";
if($item->post_type == 'page') {
if ($item->hasChildren && $depth == 0) {
$item_output .= '<a'. $attributes .' class="dropdown-toggle" data-toggle="dropdown">';
} else {
$item_output .= '<a'. $attributes .'>';
}
$item_output .= apply_filters('the_title', $item->post_title, $item->ID);
if ($item->hasChildren && $depth == 0) {
$item_output .= '<b class="caret"></b></a>';
} else {
$item_output .= '</a>';
}
} else {
$item_output = $args->before;
/* If this item has a dropdown menu, make clicking on this link toggle it */
if ($item->hasChildren && $depth == 0) {
$item_output .= '<a'. $attributes .' class="dropdown-toggle" data-toggle="dropdown">';
} else {
$item_output .= '<a'. $attributes .'>';
}
//var_dump($item);
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
/* Output the actual caret for the user to click on to toggle the menu */
if ($item->hasChildren && $depth == 0) {
$item_output .= '<b class="caret"></b></a>';
} else {
$item_output .= '</a>';
}
$item_output .= $args->after;
}
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
return;
}
/* Close the <li>
* Note: the <a> is already closed
* Note 2: $depth is "correct" at this level
*/
function end_el (&$output, $item, $depth, $args)
{
$output .= '</li>';
return;
}
/* Add a 'hasChildren' property to the item
* Code from: http://wordpress.org/support/topic/how-do-i-know-if-a-menu-item-has-children-or-is-a-leaf#post-3139633
*/
function display_element ($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
{
/* if($element->post_type == 'page' && !isset($children_elements[$element->ID])) {
$children = get_children(array('post_parent' => $element->ID, 'numberposts' => -1, 'post_type' => 'page'));
$children_elements[$element->ID] = $children;
}*/
// check whether this item has children, and set $item->hasChildren accordingly
$element->hasChildren = isset($children_elements[$element->ID]) && !empty($children_elements[$element->ID]);
//var_dump($children_elements);
// var_dump($element);
/*if($element->hasChildren) {
$element2 = $children_elements[$element->ID];
$child2 = $children_elements[$element2->ID];
$element2->hasChildren = isset($child2[$element2->ID]) && !empty($child2[$element2->ID]);
}*/
// continue with normal behavior
return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
}
}
function search_menu_item($items, $args){
// Reference: http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus/
if ($args->theme_location == 'primary') {
$items = '
<li id="sitesearch">
<form id="searchForm" method="get" action="'.get_bloginfo('wpurl').'/search-results/">
<div class="input-append">
<input name="search" type="text" id="sitesearch-input" placeholder="Search this Site..."><button class="btn" type="button" value="Go" id="sbutton"><i class="icon-search"></i></button>
<input type="hidden" id="stype" name="stype" value="site">
</div>
</form>
</li>
' . $items;
}
return $items;
}
?>
You can’t perform that action at this time.