Intereting Posts
Как удалить мистический текст из текста? Изображение включено Как отображать самые популярные сообщения из определенной категории на боковой панели? Организация и заполнение сообщений (отметьте как прочитанные и скрытые) Как я могу получить список писем пользователей, которые прокомментировали сообщение? Получить ссылку на первое сообщение пользовательской таксономии в пользовательском списке таксономии Загрузка изображений в диспетчере ссылок Разделить медиа-запросы в разных файлах! Что делает загрузчик мультимедиа WordPress для загрузки файлов изображений? Пропустить первое сообщение в категории Архив Посты запросов для каждой разделяемой категории (Похожие сообщения) Почтовые запросы по широте и долготе Ошибка соединения – ошибка cURL 7 Нет возможности обновлять WP в бэкэнд клиента Мгновенная установка wordpress Комментарии ждут, но комментариев не найдено

Добавление последних сообщений в меню

Я хочу отображать последние сообщения справа в раскрывающемся меню WordPress. Для каждой подкатегории я хочу, чтобы две последние записи этой категории отображались в правой части моего подменю, когда вы наводили курсор на категорию (аналогично этому – goodlife.fuelthemes.net или theeverygirl.com/). Мое меню настроено внутри моего сайта WordPress и является основным меню. Есть ли у кого-нибудь какие-либо предложения о том, как я могу это достичь?

введите описание изображения здесь

мое текущее меню – https://jsfiddle.net/phz835re/1/

header.php

<?php /** */ ?> <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <div id="ht-page"> <header id="ht-masthead" class="ht-site-header"> <div id="ht-site-branding"> <?php get_template_part( 'hamburgermenu' ); ?> <?php if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) : the_custom_logo(); else : if ( is_front_page() ) : ?> <h1 class="ht-site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> <?php else : ?> <p class="ht-site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p> <?php endif; ?> <p class="ht-site-description"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'description' ); ?></a></p> <?php endif; ?> </div><!-- .site-branding --> <nav id="ht-site-navigation" class="ht-main-navigation"> <?php wp_nav_menu( array( 'theme_location' => 'primary', 'container_class' => 'ht-menu ht-clearfix' , 'menu_class' => 'ht-clearfix', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', ) ); ?> </nav><!-- #ht-site-navigation --> <?php get_template_part( 'searchform' ); ?> </div> </header><!-- #ht-masthead --> <div id="ht-content" class="ht-site-content ht-clearfix"> 

CSS

 /*-------------------------------------------------------------- ## Header --------------------------------------------------------------*/ #ht-masthead{ background: #fff; height: 70px; border-bottom: 1px solid #eee; z-index: 99; transition: height 0.3s ease; -moz-transition: height 0.3s ease; -webkit-transition: height 0.3s ease; position: fixed; display: flex; justify-content: space-between; width: 100%; } .ht-site-title{ font-family: 'futura_tbold'; font-size: 27px; text-transform: uppercase; letter-spacing: 6px; line-height: 70; display:inline-block; transition: padding 0.3s ease; -moz-transition: padding 0.3s ease; -webkit-transition: padding 0.3s ease; margin-bottom: 19px; } .ht-site-title a{ text-decoration: none; color: #000; } .ht-site-title a:hover{ text-decoration: none; color: #000; } .ht-site-description{ color: #EEE; margin: 0; font-size: 15px; font-style: italic; line-height: 1; } .ht-site-description a{ color: #333; } #ht-site-branding { display: flex; align-items: center; } /*-------------------------------------------------------------- ## Menus --------------------------------------------------------------*/ #ht-site-navigation { display: flex; } .ht-sticky #ht-site-navigation { padding: 17px 0; } .ht-main-navigation .ht-menu {} .ht-main-navigation ul { list-style: none; margin: 0; padding-left: 0; display: inline-block; position: relative; } .ht-main-navigation li { float: left; } .ht-main-navigation a { display: block; text-decoration: none; color: #000; text-transform: uppercase; font-size: 15px; font-family: 'Raleway', sans-serif; line-height: 70px; padding: 0 15px; font-weight: 600; letter-spacing: 2px; padding-bottom: 40px; margin-left: 31px; } .ht-main-navigation ul ul { position: absolute; left: 0; top: 100%; background: #FFF; min-width: 200px; right:0; z-index: 999; padding: 8px; margin-top:-40px; box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.05); height:300px; transform: scaleY(0); -webkit-transform-origin: top; -moz-transform-origin: top; transform-origin: top; -webkit-transition: all .3s ease-in-out; -moz-transition: all .3s ease-in-out; opacity: 0; } .ht-sticky .ht-main-navigation ul ul { margin-top: 17px; } .ht-sticky .ht-main-navigation ul ul ul { margin-top: 0; } .ht-main-navigation ul ul a { text-transform: uppercase; font-weight: 400; color: #444; line-height: 1.5; padding: 10px 15px; font-size: 14px; text-align: left; } .ht-main-navigation ul ul li { float: none; margin: 0 0 5px; } .ht-main-navigation ul ul li:last-child { margin-bottom: 0; } .ht-main-navigation ul li:hover > ul { opacity: 1; transform: scaleY(1); } .page-template-home-template .ht-main-navigation .current_page_item > a, .page-template-home-template .ht-main-navigation .current-menu-item > a, .page-template-home-template .ht-main-navigation .current_page_ancestor > a, .home.blog .ht-main-navigation .current_page_item > a, .home.blog .ht-main-navigation .current-menu-item > a, .home.blog .ht-main-navigation .current_page_ancestor > a { background: none; color: inherit; } .ht-main-navigation li:hover > a, .page-template-home-template .ht-main-navigation li:hover > a, .home.blog .ht-main-navigation li:hover > a, .ht-main-navigation .current_page_item > a, .ht-main-navigation .current-menu-item > a, .ht-main-navigation .current_page_ancestor > a, .page-template-home-template .ht-main-navigation .current > a, .home.blog .ht-main-navigation .current > a { color: #000; text-decoration: none; } .site-main .comment-navigation, .site-main .posts-navigation, .site-main .post-navigation { margin: 0 0 15px; overflow: hidden; } .comment-navigation .nav-previous, .posts-navigation .nav-previous, .post-navigation .nav-previous { float: left; width: 50%; } .comment-navigation .nav-next, .posts-navigation .nav-next, .post-navigation .nav-next { float: right; text-align: right; width: 50%; } .owl-item img{ height: 256px; width:256px !important; } 

functions.php

 <?php define( 'WP_DEBUG', true ); function btc_scripts() { wp_enqueue_style('style', get_stylesheet_uri()); wp_enqueue_style( 'bootstrap-style', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.7' ); wp_enqueue_script ( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '3.3.7', true); } add_action( 'wp_enqueue_scripts', 'btc_scripts' ); //Navigation Menus register_nav_menus(array( 'primary' => __('Primary Menu'), 'footer' => __( 'Footer Menu'), )); class CSS_Menu_Walker extends Walker { var $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id'); function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul>\n"; } function end_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $wp_query; $indent = ($depth) ? str_repeat("\t", $depth) : ''; $class_names = $value = ''; $classes = empty($item->classes) ? array() : (array) $item->classes; /* Add active class */ if (in_array('current-menu-item', $classes)) { $classes[] = 'active'; unset($classes['current-menu-item']); } /* Check for children */ $children = get_posts(array('post_type' => 'nav_menu_item', 'nopaging' => true, 'numberposts' => 1, 'meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $item->ID)); if (!empty($children)) { $classes[] = 'has-sub'; } $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args)); $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; $id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args); $id = $id ? ' id="' . esc_attr($id) . '"' : ''; $output .= $indent . '<li' . $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 ) .'"' : ''; $attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url ) .'"' : ''; $item_output = $args->before; $item_output .= '<a'. $attributes .'><span>'; $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; $item_output .= '</span></a>'; $item_output .= $args->after; $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); } function end_el(&$output, $item, $depth = 0, $args = array()) { $output .= "</li>\n"; } } // Add Widget Areas function ourWidgetsInit() { register_sidebar( array( 'name' => 'Sidebar', 'id' => 'sidebar1', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 1', 'id' => 'footer1', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 2', 'id' => 'footer2', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 3', 'id' => 'footer3', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 4', 'id' => 'footer4', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); } add_action('widgets_init', 'ourWidgetsInit'); // Theme setup function learningWordpress_setup() { // Navigation Menus register_nav_menus(array( 'primary' => __('Primary Menu'), 'footer' => __( 'Footer Menu'), )); // Add featured image support add_theme_support('post-thumbnails'); add_image_size('medium-thumbnail', 446, 345, true); add_image_size('large-thumbnail', 1386, 595, true); add_image_size('popular-posts', 256, 256, true); } add_action('after_setup_theme', 'learningWordpress_setup'); // Register Custom Taxonomy function location() { $labels = array( 'name' => 'Locations', 'singular_name' => 'Location', 'menu_name' => 'Location', 'all_items' => 'All Items', 'parent_item' => 'Parent Item', 'parent_item_colon' => 'Parent Item:', 'new_item_name' => 'New Item Name', 'add_new_item' => 'Add New Item', 'edit_item' => 'Edit Item', 'update_item' => 'Update Item', 'view_item' => 'View Item', 'separate_items_with_commas' => 'Separate items with commas', 'add_or_remove_items' => 'Add or remove items', 'choose_from_most_used' => 'Choose from the most used', 'popular_items' => 'Popular Items', 'search_items' => 'Search Items', 'not_found' => 'Not Found', 'no_terms' => 'No items', 'items_list' => 'Items list', 'items_list_navigation' => 'Items list navigation', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'location', array( 'post' ), $args ); } add_action( 'init', 'location', 0 ); // Carousel function carousel_scripts() { wp_enqueue_style( 'owl.carousel', get_template_directory_uri() . '/css/owl.carousel.css' ); wp_enqueue_style( 'owl.theme', get_template_directory_uri() . '/css/owl.theme.css' ); wp_enqueue_script( 'owl.carousel', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), '20120206', true ); wp_enqueue_script( 'effects', get_template_directory_uri() . '/js/effects.js', array('jquery'), '20120206', true ); } add_action( 'wp_enqueue_scripts', 'carousel_scripts' ); // Custom control for carousel category if (class_exists('WP_Customize_Control')) { class WP_Customize_Category_Control extends WP_Customize_Control { public function render_content() { $dropdown = wp_dropdown_categories( array( 'name' => '_customize-dropdown-category-' . $this->id, 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => $this->value(), ) ); $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown ); printf( '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>', $this->label, $dropdown ); } } } // Register slider customizer section add_action( 'customize_register' , 'carousel_options' ); function carousel_options( $wp_customize ) { $wp_customize->add_section( 'carousel_section', array( 'title' => 'Carousel settings', 'priority' => 202, 'capability' => 'edit_theme_options', ) ); $wp_customize->add_setting( 'carousel_setting', array( 'default' => '', ) ); $wp_customize->add_control( new WP_Customize_category_Control( $wp_customize, 'carousel_category', array( 'label' => 'Category', 'settings' => 'carousel_setting', 'section' => 'carousel_section' ) ) ); $wp_customize->add_setting( 'count_setting', array( 'default' => '6', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'carousel_count', array( 'label' => __( 'Number of posts', 'theme_name' ), 'section' => 'carousel_section', 'settings' => 'count_setting', 'type' => 'text', ) ) ); } //JQUERY function my_theme_scripts() { wp_enqueue_script( 'my-great-script', get_template_directory_uri() . '/js/loadmore.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'my_theme_scripts' ); //MORE J function my_admin_scripts() { wp_enqueue_script( 'my-great-script', plugin_dir_url(' /js/fontend.min.js' ) . '/js/fontend.min.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'admin_enqueue_scripts', 'my_admin_scripts' ); //MORE COMMENTS /** * Return the default comment form fields. * Customize comment form default fields. * Move the comment_field below the author, email, and url fields. */ function wpse250243_comment_form_default_fields( $fields ) { $commenter = wp_get_current_commenter(); $user = wp_get_current_user(); $user_identity = $user->exists() ? $user->display_name : ''; $req = get_option( 'require_name_email' ); $aria_req = ( $req ? " aria-required='true'" : '' ); $fields = [ 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( '', 'textdomain' ) . ( $req ? ' <span class="required"></span>' : '' ) . '</label> ' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', 'email' => '<p class="comment-form-email"><label for="email">' . __( '', 'textdomain' ) . ( $req ? ' <span class="required"></span>' : '' ) . '</label> ' . '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', 'url' => '<p class="comment-form-url"><label for="url">' . __( '', 'textdomain' ) . '</label> ' . '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', ]; return $fields; } add_filter( 'comment_form_default_fields', 'wpse250243_comment_form_default_fields' ); /** * Remove the original comment field because we've added it to the default fields * using wpse250243_comment_form_default_fields(). If we don't do this, the comment * field will appear twice. */ function wpse250243_comment_form_defaults( $defaults ) { if ( isset( $defaults[ 'comment_field' ] ) ) { $defaults[ 'comment_field' ] = ''; } return $defaults; } add_filter( 'comment_form_defaults', 'wpse250243_comment_form_defaults', 10, 1 ); //MOVE COMMENTS function wpb_move_comment_field_to_bottom( $fields ) { $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; return $fields; } add_filter( 'comment_form_fields', 'wpb_move_comment_field_to_bottom' ); //COMMENTS add_filter( 'comment_form_default_fields', 'wpse_62742_comment_placeholders' ); /** * Change default fields, add placeholder and change type attributes. * * @param array $fields * @return array */ function wpse_62742_comment_placeholders( $fields ) { $fields['author'] = str_replace( '<input', '<input placeholder="' /* Replace 'theme_text_domain' with your theme's text domain. * I use _x() here to make your translators life easier. :) * See http://codex.wordpress.org/Function_Reference/_x */ . _x( 'Name', 'comment form placeholder', 'theme_text_domain' ) . '"', $fields['author'] ); $fields['email'] = str_replace( '<input id="email" name="email" type="text"', /* We use a proper type attribute to make use of the browser's * validation, and to get the matching keyboard on smartphones. */ '<input type="email" placeholder="Email" id="email" name="email"', $fields['email'] ); $fields['url'] = str_replace( '<input id="url" name="url" type="text"', // Again: a better 'type' attribute value. '<input placeholder="Website" id="url" name="url" type="url"', $fields['url'] ); return $fields; } //Comments Continued if ( get_option ('thread_comments') ) { wp_enqueue_script('comment-reply'); } //Comments function custom_comments ($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>"> <div id="comment-<?php comment_ID(); ?>"> <header class="comment-author-vcard"> <?php printf (__('<cite_class="fn">%s</cite> <span class="says"></span>'), get_comment_author_link()) ?> </header> <div class="comment-meta"><a href="<?php echo htmlspecialchars( get_comment_link($comment->comment_ID )) ?>"></a></div> <?php if ($comment->comment_approved == '0') : ?> <em><?php _e('Your comment is awaiting moderation.') ?></em> <?php endif; ?> <div class="comment-content"><?php comment_text() ?></div> <div class="comment-time"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time() ) ?><?php edit_comment_link(__('(Edit)'), ' ', ' ') ?><?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'] ))) ?></div> <div class="reply"> </div> </div> <?php } //New Menus function register_my_menus() { register_nav_menus( array( 'new-menu' => __( 'Footer Menu Secondary' ), 'another-menu' => __( 'Another Menu' ), 'an-extra-menu' => __( 'An Extra Menu' ) ) ); } add_action( 'init', 'register_my_menus' ); // WordPress function load_fonts() { wp_register_style('et-googleFonts', 'https://fonts.googleapis.com/css?family=David+Libre|Crimson+Text|Questrial|Raleway:200,300,400,600,700|Montserrat|Catamaran|Pathway+Gothic+One|PT+Serif|Days+One|Lato:300,400,700|Work+Sans:400,500,600,700'); wp_enqueue_style( 'et-googleFonts'); } add_action('wp_print_styles', 'load_fonts'); //REMOVE P function filter_ptags_on_images($content){ return preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '\1', $content); } add_filter('the_content', 'filter_ptags_on_images'); // Popular Posts function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, 0); }else{ $count++; update_post_meta($postID, $count_key, $count); } } //To keep the count accurate, lets get rid of prefetching remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); function wpb_track_post_views ($post_id) { if ( !is_single() ) return; if ( empty ( $post_id) ) { global $post; $post_id = $post->ID; } wpb_set_post_views($post_id); } add_action( 'wp_head', 'wpb_track_post_views'); //search function searchfunction() { wp_enqueue_script ( 'search-function', get_template_directory_uri() . '/js/search.js', array('jquery'), '2.2.4', true); } add_action( 'wp_enqueue_scripts', 'searchfunction' ); //hamburger menu function hamburgermenu() { wp_enqueue_script( 'hamburger-menu', get_stylesheet_directory_uri() . '/js/hamburgermenu.js', array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'hamburgermenu' ); //instagram footer function instagramfooter() { wp_enqueue_script ( 'instagram-footer', get_template_directory_uri() . '/js/instagramfooter.js', array('jquery'), '2.2.4', true); } add_action( 'wp_enqueue_scripts', 'instagramfooter' ); //font awesome function wpb_load_fa() { wp_enqueue_style( 'wpb-fa', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' ); } add_action( 'wp_enqueue_scripts', 'wpb_load_fa' ); //font awesome function loadmoreposts() { wp_enqueue_script( 'load-more-posts', get_template_directory_uri() . '/js/loadmore-posts.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'loadmoreposts' ); не <?php define( 'WP_DEBUG', true ); function btc_scripts() { wp_enqueue_style('style', get_stylesheet_uri()); wp_enqueue_style( 'bootstrap-style', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.7' ); wp_enqueue_script ( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '3.3.7', true); } add_action( 'wp_enqueue_scripts', 'btc_scripts' ); //Navigation Menus register_nav_menus(array( 'primary' => __('Primary Menu'), 'footer' => __( 'Footer Menu'), )); class CSS_Menu_Walker extends Walker { var $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id'); function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul>\n"; } function end_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $wp_query; $indent = ($depth) ? str_repeat("\t", $depth) : ''; $class_names = $value = ''; $classes = empty($item->classes) ? array() : (array) $item->classes; /* Add active class */ if (in_array('current-menu-item', $classes)) { $classes[] = 'active'; unset($classes['current-menu-item']); } /* Check for children */ $children = get_posts(array('post_type' => 'nav_menu_item', 'nopaging' => true, 'numberposts' => 1, 'meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $item->ID)); if (!empty($children)) { $classes[] = 'has-sub'; } $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args)); $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; $id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args); $id = $id ? ' id="' . esc_attr($id) . '"' : ''; $output .= $indent . '<li' . $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 ) .'"' : ''; $attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url ) .'"' : ''; $item_output = $args->before; $item_output .= '<a'. $attributes .'><span>'; $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; $item_output .= '</span></a>'; $item_output .= $args->after; $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); } function end_el(&$output, $item, $depth = 0, $args = array()) { $output .= "</li>\n"; } } // Add Widget Areas function ourWidgetsInit() { register_sidebar( array( 'name' => 'Sidebar', 'id' => 'sidebar1', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 1', 'id' => 'footer1', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 2', 'id' => 'footer2', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 3', 'id' => 'footer3', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); register_sidebar( array( 'name' => 'Footer Area 4', 'id' => 'footer4', 'before_widget' => '<div class="widget-item">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); } add_action('widgets_init', 'ourWidgetsInit'); // Theme setup function learningWordpress_setup() { // Navigation Menus register_nav_menus(array( 'primary' => __('Primary Menu'), 'footer' => __( 'Footer Menu'), )); // Add featured image support add_theme_support('post-thumbnails'); add_image_size('medium-thumbnail', 446, 345, true); add_image_size('large-thumbnail', 1386, 595, true); add_image_size('popular-posts', 256, 256, true); } add_action('after_setup_theme', 'learningWordpress_setup'); // Register Custom Taxonomy function location() { $labels = array( 'name' => 'Locations', 'singular_name' => 'Location', 'menu_name' => 'Location', 'all_items' => 'All Items', 'parent_item' => 'Parent Item', 'parent_item_colon' => 'Parent Item:', 'new_item_name' => 'New Item Name', 'add_new_item' => 'Add New Item', 'edit_item' => 'Edit Item', 'update_item' => 'Update Item', 'view_item' => 'View Item', 'separate_items_with_commas' => 'Separate items with commas', 'add_or_remove_items' => 'Add or remove items', 'choose_from_most_used' => 'Choose from the most used', 'popular_items' => 'Popular Items', 'search_items' => 'Search Items', 'not_found' => 'Not Found', 'no_terms' => 'No items', 'items_list' => 'Items list', 'items_list_navigation' => 'Items list navigation', ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'location', array( 'post' ), $args ); } add_action( 'init', 'location', 0 ); // Carousel function carousel_scripts() { wp_enqueue_style( 'owl.carousel', get_template_directory_uri() . '/css/owl.carousel.css' ); wp_enqueue_style( 'owl.theme', get_template_directory_uri() . '/css/owl.theme.css' ); wp_enqueue_script( 'owl.carousel', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), '20120206', true ); wp_enqueue_script( 'effects', get_template_directory_uri() . '/js/effects.js', array('jquery'), '20120206', true ); } add_action( 'wp_enqueue_scripts', 'carousel_scripts' ); // Custom control for carousel category if (class_exists('WP_Customize_Control')) { class WP_Customize_Category_Control extends WP_Customize_Control { public function render_content() { $dropdown = wp_dropdown_categories( array( 'name' => '_customize-dropdown-category-' . $this->id, 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => $this->value(), ) ); $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown ); printf( '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>', $this->label, $dropdown ); } } } // Register slider customizer section add_action( 'customize_register' , 'carousel_options' ); function carousel_options( $wp_customize ) { $wp_customize->add_section( 'carousel_section', array( 'title' => 'Carousel settings', 'priority' => 202, 'capability' => 'edit_theme_options', ) ); $wp_customize->add_setting( 'carousel_setting', array( 'default' => '', ) ); $wp_customize->add_control( new WP_Customize_category_Control( $wp_customize, 'carousel_category', array( 'label' => 'Category', 'settings' => 'carousel_setting', 'section' => 'carousel_section' ) ) ); $wp_customize->add_setting( 'count_setting', array( 'default' => '6', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'carousel_count', array( 'label' => __( 'Number of posts', 'theme_name' ), 'section' => 'carousel_section', 'settings' => 'count_setting', 'type' => 'text', ) ) ); } //JQUERY function my_theme_scripts() { wp_enqueue_script( 'my-great-script', get_template_directory_uri() . '/js/loadmore.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'my_theme_scripts' ); //MORE J function my_admin_scripts() { wp_enqueue_script( 'my-great-script', plugin_dir_url(' /js/fontend.min.js' ) . '/js/fontend.min.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'admin_enqueue_scripts', 'my_admin_scripts' ); //MORE COMMENTS /** * Return the default comment form fields. * Customize comment form default fields. * Move the comment_field below the author, email, and url fields. */ function wpse250243_comment_form_default_fields( $fields ) { $commenter = wp_get_current_commenter(); $user = wp_get_current_user(); $user_identity = $user->exists() ? $user->display_name : ''; $req = get_option( 'require_name_email' ); $aria_req = ( $req ? " aria-required='true'" : '' ); $fields = [ 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( '', 'textdomain' ) . ( $req ? ' <span class="required"></span>' : '' ) . '</label> ' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', 'email' => '<p class="comment-form-email"><label for="email">' . __( '', 'textdomain' ) . ( $req ? ' <span class="required"></span>' : '' ) . '</label> ' . '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', 'url' => '<p class="comment-form-url"><label for="url">' . __( '', 'textdomain' ) . '</label> ' . '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', ]; return $fields; } add_filter( 'comment_form_default_fields', 'wpse250243_comment_form_default_fields' ); /** * Remove the original comment field because we've added it to the default fields * using wpse250243_comment_form_default_fields(). If we don't do this, the comment * field will appear twice. */ function wpse250243_comment_form_defaults( $defaults ) { if ( isset( $defaults[ 'comment_field' ] ) ) { $defaults[ 'comment_field' ] = ''; } return $defaults; } add_filter( 'comment_form_defaults', 'wpse250243_comment_form_defaults', 10, 1 ); //MOVE COMMENTS function wpb_move_comment_field_to_bottom( $fields ) { $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; return $fields; } add_filter( 'comment_form_fields', 'wpb_move_comment_field_to_bottom' ); //COMMENTS add_filter( 'comment_form_default_fields', 'wpse_62742_comment_placeholders' ); /** * Change default fields, add placeholder and change type attributes. * * @param array $fields * @return array */ function wpse_62742_comment_placeholders( $fields ) { $fields['author'] = str_replace( '<input', '<input placeholder="' /* Replace 'theme_text_domain' with your theme's text domain. * I use _x() here to make your translators life easier. :) * See http://codex.wordpress.org/Function_Reference/_x */ . _x( 'Name', 'comment form placeholder', 'theme_text_domain' ) . '"', $fields['author'] ); $fields['email'] = str_replace( '<input id="email" name="email" type="text"', /* We use a proper type attribute to make use of the browser's * validation, and to get the matching keyboard on smartphones. */ '<input type="email" placeholder="Email" id="email" name="email"', $fields['email'] ); $fields['url'] = str_replace( '<input id="url" name="url" type="text"', // Again: a better 'type' attribute value. '<input placeholder="Website" id="url" name="url" type="url"', $fields['url'] ); return $fields; } //Comments Continued if ( get_option ('thread_comments') ) { wp_enqueue_script('comment-reply'); } //Comments function custom_comments ($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>"> <div id="comment-<?php comment_ID(); ?>"> <header class="comment-author-vcard"> <?php printf (__('<cite_class="fn">%s</cite> <span class="says"></span>'), get_comment_author_link()) ?> </header> <div class="comment-meta"><a href="<?php echo htmlspecialchars( get_comment_link($comment->comment_ID )) ?>"></a></div> <?php if ($comment->comment_approved == '0') : ?> <em><?php _e('Your comment is awaiting moderation.') ?></em> <?php endif; ?> <div class="comment-content"><?php comment_text() ?></div> <div class="comment-time"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time() ) ?><?php edit_comment_link(__('(Edit)'), ' ', ' ') ?><?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'] ))) ?></div> <div class="reply"> </div> </div> <?php } //New Menus function register_my_menus() { register_nav_menus( array( 'new-menu' => __( 'Footer Menu Secondary' ), 'another-menu' => __( 'Another Menu' ), 'an-extra-menu' => __( 'An Extra Menu' ) ) ); } add_action( 'init', 'register_my_menus' ); // WordPress function load_fonts() { wp_register_style('et-googleFonts', 'https://fonts.googleapis.com/css?family=David+Libre|Crimson+Text|Questrial|Raleway:200,300,400,600,700|Montserrat|Catamaran|Pathway+Gothic+One|PT+Serif|Days+One|Lato:300,400,700|Work+Sans:400,500,600,700'); wp_enqueue_style( 'et-googleFonts'); } add_action('wp_print_styles', 'load_fonts'); //REMOVE P function filter_ptags_on_images($content){ return preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '\1', $content); } add_filter('the_content', 'filter_ptags_on_images'); // Popular Posts function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, 0); }else{ $count++; update_post_meta($postID, $count_key, $count); } } //To keep the count accurate, lets get rid of prefetching remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); function wpb_track_post_views ($post_id) { if ( !is_single() ) return; if ( empty ( $post_id) ) { global $post; $post_id = $post->ID; } wpb_set_post_views($post_id); } add_action( 'wp_head', 'wpb_track_post_views'); //search function searchfunction() { wp_enqueue_script ( 'search-function', get_template_directory_uri() . '/js/search.js', array('jquery'), '2.2.4', true); } add_action( 'wp_enqueue_scripts', 'searchfunction' ); //hamburger menu function hamburgermenu() { wp_enqueue_script( 'hamburger-menu', get_stylesheet_directory_uri() . '/js/hamburgermenu.js', array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'hamburgermenu' ); //instagram footer function instagramfooter() { wp_enqueue_script ( 'instagram-footer', get_template_directory_uri() . '/js/instagramfooter.js', array('jquery'), '2.2.4', true); } add_action( 'wp_enqueue_scripts', 'instagramfooter' ); //font awesome function wpb_load_fa() { wp_enqueue_style( 'wpb-fa', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' ); } add_action( 'wp_enqueue_scripts', 'wpb_load_fa' ); //font awesome function loadmoreposts() { wp_enqueue_script( 'load-more-posts', get_template_directory_uri() . '/js/loadmore-posts.js', array( 'jquery' ), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'loadmoreposts' );