Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
HRI
March 2014
by UITS Web Lab
brian.dunnigan@uconn.edu
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
add_theme_support( 'post-thumbnails' );
// register the menus
function register_my_menus() {
register_nav_menu( 'primary', __( 'Primary Menu', 'hri' ) );
}
add_action( 'init', 'register_my_menus' );
function get_post_thumbnail_caption() {
if ( $thumb = get_post_thumbnail_id() )
return get_post( $thumb )->post_excerpt;
}
add_action( 'init', 'create_post_type' );
function create_post_type() {
$labels = array(
'name' => _x( 'Faculty/Staff', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Faculty/Staff', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Faculty/Staff', 'text_domain' ),
'parent_item_colon' => __( 'Parent Faculty/Staff:', 'text_domain' ),
'all_items' => __( 'All Faculty/Staff', 'text_domain' ),
'view_item' => __( 'View Faculty/Staff', 'text_domain' ),
'add_new_item' => __( 'Add Faculty/Staff', 'text_domain' ),
'add_new' => __( 'New Faculty/Staff', 'text_domain' ),
'edit_item' => __( 'Edit Faculty/Staff', 'text_domain' ),
'update_item' => __( 'Update Faculty/Staff', 'text_domain' ),
'search_items' => __( 'Search Faculty/Staff', 'text_domain' ),
'not_found' => __( 'No Faculty/Staff found', 'text_domain' ),
'not_found_in_trash' => __( 'No Faculty/Staff found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'Faculty/Staff', 'text_domain' ),
'description' => __( 'Faculty/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' => 'faculty_staff',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => array('slug' => 'faculty_staff'),
);
register_post_type( 'faculty_staff', $args );
}
function my_cpt_post_types( $post_types ) {
$post_types[] = 'faculty_staff';
return $post_types;
}
add_filter( 'cpt_post_types', 'my_cpt_post_types' );
/* Flush rewrite rules for custom post types. */
add_action( 'after_switch_theme', 'bt_flush_rewrite_rules' );
/* Flush your rewrite rules */
function bt_flush_rewrite_rules() {
flush_rewrite_rules();
}
function custom_excerpt_length( $length ) {
return 27;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
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' );
/*
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' => 'Home - Calendar',
'id' => 'home-calendar',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home - Slideshow',
'id' => 'sidebar-slideshow',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - About Us 1',
'id' => 'sidebar-about1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - About Us 2',
'id' => 'sidebar-about2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - About Us 3',
'id' => 'sidebar-about3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Academic Programs 1',
'id' => 'sidebar-academic1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Academic Programs 2',
'id' => 'sidebar-academic2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Academic Programs 3',
'id' => 'sidebar-academic3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Research Programs 1',
'id' => 'sidebar-research1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Research Programs 2',
'id' => 'sidebar-research2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Research Programs 3',
'id' => 'sidebar-research3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Events 1',
'id' => 'sidebar-events1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Events 2',
'id' => 'sidebar-events2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Events 3',
'id' => 'sidebar-events3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Resources 1',
'id' => 'sidebar-resources1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Resources 2',
'id' => 'sidebar-resources2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Resources 3',
'id' => 'sidebar-resources3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Awards &amp; Fellowships 1',
'id' => 'sidebar-awards1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Awards &amp; Fellowships 2',
'id' => 'sidebar-awards2',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Awards &amp; Fellowships 3',
'id' => 'sidebar-awards3',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Sidebar - Contact',
'id' => 'sidebar-contact1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
}
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( 'jquery-ui-tabs', array('jquery') );
wp_enqueue_script('uc-hale-custom', get_bloginfo('template_url').'/js/custom.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');
add_action( 'wp_ajax_clas_post_title', 'prefix_ajax_clas_post_title' );
add_action('wp_ajax_nopriv_clas_post_title', 'prefix_ajax_clas_post_title');
function prefix_ajax_clas_post_title(){
$id = $_POST['data'];
$content_post = get_post($id);
$object = new stdClass();
header('Content-type: application/json');
echo json_encode($object);
die();
}
add_action( 'wp_ajax_clas_post_content', 'prefix_ajax_clas_post_content' );
add_action('wp_ajax_nopriv_clas_post_content', 'prefix_ajax_clas_post_content');
function prefix_ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive
$id = $_POST['postID'];
$content_post = get_post($id);
$content = do_shortcode(wpautop($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;
header('Content-type: application/json');
echo json_encode($object);
die();
}
add_action( 'wp_ajax_clas_tag_posts', 'prefix_ajax_clas_tag_posts' );
add_action('wp_ajax_nopriv_clas_tag_posts', 'prefix_ajax_clas_tag_posts');
function prefix_ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name
$tag = $_POST['val'];
$args = "tag='".$tag."'&orderby=post-date&field=ids";
$ids = get_posts( $args );
if( $tag == 'All News' ){
$ids = get_posts( 'orderby=post-date&field=ids&numberposts=-1' );
}
$object = new stdClass();
foreach( $ids as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;
}
header('Content-type: application/json');
echo json_encode($object);
die();
}
//Bootstrap whitelist
/*function add_allowed_tags($tags) {
$newtags = array(
'div',
'ul',
'li',
'button',
'a');
$newattrs = array(
'data-toggle' => true,
'data-dismiss' => true,
'data-target' => true,
'data-spy' => true,
'data-loading-text' => true,
'data-parent' => true,
'data-slide' => true,
'data-slide-to' => true,
'data-provide' => true,
'data-interval' => true,
'data-pause' => true,
'data-animation' => true,
'data-html' => true,
'data-placement' => true,
'data-selector' => true,
'data-title' => true,
'data-trigger' => true,
'data-delay' => true,
'data-container' => true);
foreach($newtags as $newtag){
if( isset($tags[$newtag]) && is_array($tags[$newtag])){
$tags[$newtag] = array_merge($tags[$newtag], $newattrs);
}
else{
$tags[$newtag] = $newattrs;
}
}
return $tags;
}
add_filter('wp_kses_allowed_html', 'add_allowed_tags');*/
add_action( 'wp_ajax_clas_cat_posts', 'prefix_ajax_clas_cat_posts' );
add_action('wp_ajax_nopriv_clas_cat_posts', 'prefix_ajax_clas_cat_posts');
function prefix_ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id
$json = $_POST['data'];
$tax = $json['taxonomy'];
$val = $json['value'];
if( $tax == 'category' ){
$args = "category='".$val."'&orderby=post-date&field=ids&numberposts=-1";
} else if( $tax == 'tag' ) {
$args = "tag_id=".$val."&orderby=post-date&field=ids&numberposts=-1";
}
$ids = get_posts( $args );
if( $val == "0" ){
$ids = get_posts( 'orderby=post-date&field=ids&numberposts=-1' );
}
$object = new stdClass();
foreach( $ids as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;
}
header('Content-type: application/json');
echo json_encode($object);
die();
}
add_action( 'wp_ajax_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts' );
add_action('wp_ajax_nopriv_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts');
function prefix_ajax_clas_orderby_posts() { //Retrieves and sorts posts by date
$order = $_POST['order'];
$args = "order=".$order."&orderby=post-date&field=ids&numberposts=-1";
$posts = get_posts( $args );
$object = new stdClass();
foreach( $posts as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;
}
header('Content-type: application/json');
echo json_encode($object);
die();
}
class hriRSS extends WP_Widget {
function hriRSS(){
$widget_ops = array(
'description' => 'Widget to display events from RSS',
'classname' => 'uc-hri-rss'
);
$this->WP_Widget('hri-rss-events', __('HRI Events Widget'), $widget_ops);
}
public function widget( $args, $instance ){
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$rss = urldecode($instance['rss_feed']);
$num = $instance['num_events'];
echo $before_widget;
if( !empty($title) ){
//echo $before_title . htmlspecialchars($title) . $after_title;
echo '<h3 class="text-serif">'.htmlspecialchars($title).'</h3><hr>';
}
if( !empty($rss) && !empty($num) ){
try {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $rss);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
curl_close($curl);
$x = simplexml_load_string($content);
//$content = file_get_contents($rss);
//$x = new SimpleXmlElement($content);
echo "<div class='uc-cal uc-listcal'><ul class='uc-cal-list'>";
$i = 0;
while ($i < $num){
$linkXML = $x->channel->item[$i]->link;
$dateStr = substr(strval($linkXML), -10);
$date = date( "F d, Y", strtotime($dateStr) );
echo "<li class='uc-cal-item'><a class='uc-cal-event' href=\"" . $linkXML . "\" title=\"" . $x->channel->item[$i]->title . "\" target=\"_blank\"><span class='uc-cal-event-date'>".$date."</span><em class='uc-cal-event-title'>" . $x->channel->item[$i]->title . "</em></a></li>";
$i++;
}
echo "</ul></div>";
}
catch (Exception $e) {
echo "<p>The blog feed doesn't seem to be available at the moment...</p>";
}
}
echo $after_widget;
}
public function form( $instance ){
$defaults = array( 'title' => __('Upcoming Events'), 'rss_feed' => __(''), 'num_events' => __(5) );
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id('title') ?>"> Widget Title:</label>
<input type="text" class="widefat" value="<?php echo htmlspecialchars($instance['title']) ?>" id="<?php echo $this->get_field_id('title') ?>" name="<?php echo $this->get_field_name('title') ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('rss_feed')?>" > RSS Feed:</label>
<input type="text" class="widefat" value="<?php echo htmlspecialchars(urldecode($instance['rss_feed']))?>" id="<?php echo $this->get_field_id('rss_feed')?>" name="<?php echo $this->get_field_name('rss_feed')?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('num_events')?>" > Number of Events:</label>
<input type="text" class="widefat" value="<?php echo (int)($instance['num_events'])?>" id="<?php echo $this->get_field_id('num_events')?>" name="<?php echo $this->get_field_name('num_events')?>" />
</p>
<?php
}
public function update( $new_instance, $old_instance ){
$instance['title'] = $new_instance['title'];
$instance['rss_feed'] = urlencode( $new_instance['rss_feed'] );
$instance['num_events'] = (int)( $new_instance['num_events'] );
return $instance;
}
}
add_action('widgets_init', create_function('', 'register_widget("hriRSS");'));
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)?
)
);
$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;
}
?>