コード例 #1
0
ファイル: helpers.php プロジェクト: yalmaa/little-magazine
function barcelona_thumbnail($size, $post_id = NULL, $attr = array())
{
    echo barcelona_get_thumbnail($size, $post_id, $attr);
}
コード例 #2
0
ファイル: nav-menu.php プロジェクト: yalmaa/little-magazine
    /**
     * Start the element output.
     *
     * @see Walker::start_el()
     *
     * @since 3.0.0
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @param object $item   Menu item data object.
     * @param int    $depth  Depth of menu item. Used for padding.
     * @param array  $args   An array of arguments. @see wp_nav_menu()
     * @param int    $id     Current item ID.
     */
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
    {
        $indent = $depth ? str_repeat("\t", $depth) : '';
        $classes = empty($item->classes) ? array() : (array) $item->classes;
        $classes[] = 'menu-item-' . intval($item->ID);
        $barcelona_has_mega_menu = $item->menu_item_parent == '0' && $item->barcelonamegamenu == '1';
        if ($barcelona_has_mega_menu) {
            $classes = array_unique(array_merge($classes, array('menu-item-mega-menu', 'menu-item-has-children')));
        }
        /**
         * Filter the CSS class(es) applied to a menu item's list item element.
         *
         * @since 3.0.0
         * @since 4.1.0 The `$depth` parameter was added.
         *
         * @param array  $classes The CSS classes that are applied to the menu item's `<li>` element.
         * @param object $item    The current menu item.
         * @param array  $args    An array of {@see wp_nav_menu()} arguments.
         * @param int    $depth   Depth of menu item. Used for padding.
         */
        $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
        $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
        /**
         * Filter the ID applied to a menu item's list item element.
         *
         * @since 3.0.1
         * @since 4.1.0 The `$depth` parameter was added.
         *
         * @param string $menu_id The ID that is applied to the menu item's `<li>` element.
         * @param object $item    The current menu item.
         * @param array  $args    An array of {@see wp_nav_menu()} arguments.
         * @param int    $depth   Depth of menu item. Used for padding.
         */
        $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
        $id = $id ? ' id="' . esc_attr($id) . '"' : '';
        $output .= $indent . '<li' . $id . $class_names . '>';
        /**
         * Filter the HTML attributes applied to a menu item's anchor element.
         *
         * @since 3.6.0
         * @since 4.1.0 The `$depth` parameter was added.
         *
         * @param array $atts {
         *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
         *
         *     @type string $title  Title attribute.
         *     @type string $target Target attribute.
         *     @type string $rel    The rel attribute.
         *     @type string $href   The href attribute.
         * }
         * @param object $item  The current menu item.
         * @param array  $args  An array of {@see wp_nav_menu()} arguments.
         * @param int    $depth Depth of menu item. Used for padding.
         */
        $atts = array();
        $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
        $atts['target'] = !empty($item->target) ? $item->target : '';
        $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
        $atts['href'] = !empty($item->url) ? $item->url : '';
        $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
        $attributes = '';
        foreach ($atts as $attr => $value) {
            if (!empty($value)) {
                $value = 'href' === $attr ? esc_url($value) : esc_attr($value);
                $attributes .= ' ' . $attr . '="' . $value . '"';
            }
        }
        $item_output = $args->before;
        $item_output .= '<a' . $attributes . '>';
        /** This filter is documented in wp-includes/post-template.php */
        $item_output .= $args->link_before . do_shortcode($item->title) . $args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;
        /**
         * Filter a menu item's starting output.
         *
         * The menu item's starting output only includes `$args->before`, the opening `<a>`,
         * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
         * no filter for modifying the opening and closing `<li>` for a menu item.
         *
         * @since 3.0.0
         *
         * @param string $item_output The menu item's starting HTML output.
         * @param object $item        Menu item data object.
         * @param int    $depth       Depth of menu item. Used for padding.
         * @param array  $args        An array of {@see wp_nav_menu()} arguments.
         */
        $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
        if ($barcelona_has_mega_menu) {
            $args = array('cat' => $item->object_id, 'posts_per_page' => -1, 'post_status' => 'publish', 'ignore_sticky_posts' => 1);
            /*
             * Posts Ordering
             */
            switch (barcelona_get_option('mm_orderby')) {
                case 'views':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = '_barcelona_views';
                    break;
                case 'comments':
                    $args['orderby'] = 'comment_count';
                    break;
                case 'votes':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = '_barcelona_vote_up';
                    break;
                case 'random':
                    $args['orderby'] = 'rand';
                    break;
                case 'posts':
                    $args['orderby'] = 'post__in';
                    break;
                default:
                    $args['orderby'] = 'date';
            }
            $args['order'] = barcelona_get_option('mm_order') != 'asc' ? 'DESC' : 'ASC';
            $latest_posts = new WP_Query($args);
            $post_ids = array();
            $i = 0;
            if ($latest_posts->have_posts()) {
                $barcelona_mm_posts = '<div class="posts-wrapper row">';
                while ($latest_posts->have_posts()) {
                    $latest_posts->the_post();
                    $post_ids[] = get_the_ID();
                    $barcelona_mm_posts .= '<div class="col col-xs-3">
											<div class="post-summary post-format-' . sanitize_html_class(barcelona_get_post_format()) . '">
												<div class="post-image">
													<a href="' . esc_url(get_the_permalink()) . '" title="' . esc_attr(get_the_title()) . '">' . barcelona_psum_overlay(false) . barcelona_get_thumbnail('barcelona-sm') . '</a>
												</div>
												<div class="post-details">
													<h2 class="post-title">
														<a href="' . esc_url(get_the_permalink()) . '">' . esc_html(get_the_title()) . '</a>
													</h2>
													<ul class="post-meta no-sep">
														<li class="post-date">
															<span class="fa fa-clock-o"></span>' . get_the_time(BARCELONA_DATE_FORMAT) . '
														</li>
													</ul>
												</div>
											</div>
										</div>';
                    $i++;
                    if ($i == 4) {
                        break;
                    }
                }
                wp_reset_postdata();
                $barcelona_mm_posts .= '</div>';
                // Mega Menu Bottom
                $barcelona_mm_bottom = '<div class="mm-bottom row"><div class="col col-sm-9">';
                // Show popular tags under mega menu
                if (barcelona_get_option('show_tags_under_mm') == 'on') {
                    $tags = array();
                    foreach ($post_ids as $k) {
                        $post_tags = wp_get_post_tags($k, array('orderby' => 'count', 'order' => 'DESC'));
                        foreach ($post_tags as $tag) {
                            $tags[$tag->term_id] = $tag;
                        }
                    }
                    if (count($tags)) {
                        usort($tags, function ($a, $b) {
                            return $a->count < $b->count;
                        });
                        $tags = array_slice($tags, 0, 5);
                        $barcelona_mm_bottom .= '<div class="tag-list"><div class="title">' . esc_html__('Popular Tags:', 'barcelona') . '</div><div class="list">';
                        foreach ($tags as $tag) {
                            $barcelona_mm_bottom .= '<a href="' . esc_url(get_term_link($tag)) . '">' . esc_html($tag->name) . '</a>,';
                        }
                        $barcelona_mm_bottom = rtrim($barcelona_mm_bottom, ',') . '</div></div>';
                    }
                }
                // Add "see all" link to the bottom
                $barcelona_mm_bottom .= '</div><div class="col col-sm-3"><div class="see-all"><a href="' . esc_url($item->url) . '">' . esc_html__('See All', 'barcelona') . '</a></div></div>';
                // Close .mm-bottom
                $barcelona_mm_bottom .= '</div>';
                $output .= '<div class="mega-menu">' . $barcelona_mm_posts . $barcelona_mm_bottom . '</div>';
            }
            // have_posts
        }
    }