public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $category = $instance['category']; $unserialized_categories = unserialize($category); $cat_string = is_array($unserialized_categories) ? join(',', $unserialized_categories) : ''; $max_posts = (int) $instance['max_posts']; $autoheight = (int) $instance['autoheight']; $autoplay = (int) $instance['autoplay']; // the query $q = new WP_Query(array('orderby' => 'date', 'posts_per_page' => $max_posts > 0 && $max_posts <= 10 ? $max_posts : 5, 'category__in' => $unserialized_categories, 'meta_key' => '_thumbnail_id')); $list = '<div class="bw-widget-slider-holder">'; $list .= '<ul class="bw-widget-slider ' . ($autoplay ? 'auto-play' : '') . '" ' . ($autoplay ? 'data-speed="3000"' : '') . '>'; while ($q->have_posts()) { $q->the_post(); $size = $autoheight ? 'bw_350' : 'bw_350x300'; if (Bw::get_option('enable_lazy_image')) { $thumbnail = '<img class="lazy" data-src="' . Bw::get_image_src($size) . '" src="' . Bw::empty_img('350x300') . '" alt="">'; } else { $thumbnail = '<img src="' . Bw::get_image_src($size) . '" alt="">'; } $list .= "<li>\n\t\t\t\t<a class='image' href='" . get_permalink() . "'>\n\t\t\t\t\t{$thumbnail}\n\t\t\t\t</a>\n\t\t\t\t<div class='box'>\n\t\t\t\t\t<h4 class='bb'><a href='" . get_permalink() . "' title='" . get_the_title() . "'>" . get_the_title() . "</a></h4>\n\t\t\t\t</div>\n\t\t\t</li>"; } wp_reset_query(); $list .= "</ul>"; $list .= "</div>"; echo $list; echo $args['after_widget']; }
?> <img class="lazy" data-src="<?php echo Bw::get_image_src($thumbsize); ?> " src="<?php echo Bw::empty_img(); ?> " alt="<?php the_title(); ?> " > <?php } else { ?> <img src="<?php echo Bw::get_image_src($thumbsize); ?> " alt="<?php the_title(); ?> " > <?php } ?> </div> </div> <span class="over"></span> <?php
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', BW_THEME) : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 10; } $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true))); if ($r->have_posts()) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="bw-sidebar-posts"> <?php while ($r->have_posts()) { $r->the_post(); ?> <li class="<?php if (!has_post_thumbnail()) { echo 'auto'; } ?> "> <?php if (has_post_thumbnail()) { ?> <div class="thumb"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (Bw::get_option('enable_lazy_image')) { ?> <img class="lazy" data-src="<?php echo Bw::get_image_src('thumbnail'); ?> " src="<?php echo Bw::empty_img(); ?> " alt="" > <?php } else { ?> <img src="<?php echo Bw::get_image_src('thumbnail'); ?> " alt="" > <?php } ?> </a> </div> <?php } ?> <div class="cont <?php if (!has_post_thumbnail()) { echo ' no-thumb'; } ?> "> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php the_title(); ?> </a> <p><?php echo Bw::truncate(get_the_excerpt(), 6); ?> </p> </div> </li> <?php } ?> </ul> <?php echo $after_widget; wp_reset_postdata(); } }
public function query_by_id($time, $instance) { global $wpdb; global $post; $limit = (int) $instance['max_posts'] > 0 && (int) $instance['max_posts'] <= 10 ? (int) $instance['max_posts'] : 5; //$categories = unserialize( $instance['category'] ); //$joined_categories = is_array( $categories ) ? join( ',', $categories ) : null; if ($time !== 'bw-all-time' && $time > 0) { $joins = "\r\n\t\t\t\tLEFT JOIN {$wpdb->term_relationships} ON({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)\r\n\t\t\t\tLEFT JOIN {$wpdb->term_taxonomy} ON({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)\r\n\t\t\t\tLEFT JOIN {$wpdb->terms} ON({$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id)\r\n\t\t\t"; $where = "\r\n\t\t\t\tAND {$wpdb->term_taxonomy}.taxonomy = 'category'\r\n\t\t\t\tAND {$wpdb->terms}.term_id = '" . $time . "'\r\n\t\t\t"; } else { $joins = ''; $where = ''; } $querystr = "\r\n\t\t\t\r\n\t\t\tSELECT *, CAST({$wpdb->posts}.post_date AS DATE) as bw_date\r\n\t\t\tFROM {$wpdb->posts}\r\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\r\n\t\t\t\t\r\n\t\t\t\t" . $joins . "\r\n\t\t\t\r\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = 'post_views_count'\r\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\tAND {$wpdb->posts}.post_date < NOW()\r\n\t\t\tAND {$wpdb->posts}.post_type = 'post'\r\n\t\t\t\t\r\n\t\t\t\t" . $where . "\r\n\t\t\t\r\n\t\t\tORDER BY bw_date desc, {$wpdb->postmeta}.meta_value+0 desc\r\n\t\t\t\r\n\t\t\tLIMIT " . $limit . "\r\n\t\t\t\r\n\t\t"; $pageposts = $wpdb->get_results($querystr, object); $c = 1; echo '<ul class="bw-sidebar-posts ' . trim($time) . '">'; foreach ($pageposts as $post) { setup_postdata($post); ?> <li> <!--div class="position"> <?php echo sprintf("%02d", $c); ?> </div--> <?php if (has_post_thumbnail()) { ?> <div class="thumb"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (Bw::get_option('enable_lazy_image')) { ?> <img class="lazy" data-src="<?php echo Bw::get_image_src('thumbnail'); ?> " src="<?php echo Bw::empty_img(); ?> " alt="" > <?php } else { ?> <img src="<?php echo Bw::get_image_src('thumbnail'); ?> " alt="" > <?php } ?> </a> </div> <?php } ?> <div class="cont <?php if (!has_post_thumbnail()) { echo ' no-thumb'; } ?> "> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php the_title(); ?> </a> <p><?php echo Bw::truncate(get_the_excerpt(), 7); ?> </p> </div> </li><?php $c++; } wp_reset_postdata(); echo '</ul>'; }
<div class="bw-slider-holder billboard"> <div class="billboard-slider bw-slider <?php echo $slider_auto_play ? 'auto-play' : ''; ?> " data-transition="<?php echo $slider_transition; ?> " data-speed="<?php echo $slider_auto_play_delay; ?> "> <?php foreach ($slideposts as $post) { setup_postdata($post); $thumb_img = Bw::get_image_src('bw_980x600'); if (!empty($thumb_img)) { ?> <article class="item"> <div class="article-thumb"> <img src="<?php echo $thumb_img; ?> " alt="<?php the_title(); ?> " > </div> <div class="info">
<?php if (Bw::get_option('enable_lazy_image')) { ?> <img class="lazy" data-src="<?php echo Bw::get_image_src('thumbnail'); ?> " src="<?php echo Bw::empty_img(); ?> " alt="" > <?php } else { ?> <img src="<?php echo Bw::get_image_src('thumbnail'); ?> " alt="" > <?php } ?> </div> </div> <span class="over"></span> </div> <?php } ?> </a> <div class="article-content">
if (count($slideposts)) { ?> <div class="bw-slider-holder"> <div class="category-slider-loader"> <div class="category-slider bw-slider <?php echo $autoplay ? 'auto-play' : ''; ?> " data-speed="3000" data-transition="<?php echo !$effect ? 'slide' : $effect; ?> "> <?php foreach ($slideposts as $post) { setup_postdata($post); $thumb_img = Bw::get_image_src('bw_700x450'); if (!empty($thumb_img)) { ?> <article class="item"> <div class="article-thumb"> <img src="<?php echo $thumb_img; ?> " alt="<?php the_title(); ?> " > </div> <div class="title shadow">
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $wp_query; if (!is_array($args)) { $args = (array) $args; } // depth dependent classes $depth_classes = array('depth-' . $depth); $depth_class_names = esc_attr(implode(' ', $depth_classes)); // passed classes $classes = empty($item->classes) ? array() : (array) $item->classes; #d($classes); $class_names = esc_attr(implode(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item))); // build html $output .= '<li id="nav-item-' . $item->ID . '" class="nav-item ' . $depth_class_names . ' ' . $class_names . ' hidden">'; // link attributes $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) . '"' : ''; $attributes .= ' class="menu-link ' . ($depth > 0 ? 'sub-menu-link' : 'main-menu-link') . '"'; $item_output = sprintf('%1$s<a%2$s>%3$s%4$s%5$s%6$s</a>%7$s', $args['before'], $attributes, $args['link_before'], apply_filters('the_title', $item->title, $item->ID), $args['link_after'], $depth == 0 ? '<i class="fa fa-circle"></i>' : '', $args['after']); //the megamenu wrapper if ($depth == 0) { $item_output .= '<div class="bw-megamenu hidden bw-over"><div class="megamenu-grid">'; } if ($depth == 0 && ($item->object == 'category' || $item->object == 'post_format')) { //lets get the meta associated with the menu item to see what layout to use $menu_layout = esc_attr(get_post_meta($item->ID, 'bw_megamenu_layout', TRUE)); //$menu_layout = 'latest_posts'; $numberposts = 4; //we start of with 5 posts and decrease from here //if the menu has children then pull fewer posts if ($item->hasChildren) { $numberposts--; } if (!empty($menu_layout)) { $post_args = array('posts_per_page' => 6, 'offset' => 0, 'post_type' => 'post', 'post_status' => 'publish'); if ($item->object == 'category') { $post_args['cat'] = $item->object_id; } elseif ($item->object == 'product_cat') { $post_args['taxonomy'] = 'product_cat'; $post_args['post_type'] = 'product'; } elseif ($item->object == 'post_format') { //first get the post format information $menu_item_post_format = get_term($item->object_id, 'post_format'); $post_args['tax_query'] = array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array($menu_item_post_format->slug))); } //decrease the number of post by 2 if we have a slider if ($menu_layout == 'slider_latest_posts') { $numberposts -= 2; } global $post; //hold the post slides ids so we exclude them from the rest of the posts $slideposts_ids = array(); //create the markup for the category posts slider if ($menu_layout == 'slider_latest_posts') { //lets grab the posts that are marked as being part of the category slider $post_args['meta_query'] = array(array('key' => 'bw_category_slider', 'value' => '1')); $slideposts = new WP_Query($post_args); $item_output .= '<div class="item one-half">'; if ($slideposts->have_posts()) { $item_output .= '<div class="megamenu-slider bw-slider bw-over">'; while ($slideposts->have_posts()) { $slideposts->the_post(); //add the id to the array $slideposts_ids[] = $post->ID; $post_title = get_the_title(); $post_link = get_permalink(); $image = Bw::get_image_src('bw_475x293'); if (!empty($image)) { if ($image) { $menu_post_image = '<img src="' . $image . '" alt="' . $post_title . '">'; } else { $menu_post_image = ''; } $item_output .= '<article class="item">' . '<a class="item-url" href="' . $post_link . '">' . '<div class="article-thumb">' . '<div class="image-hide">' . '<div class="image-wrap">' . $menu_post_image . '</div>' . '</div>' . '</div>' . '<div class="title shadow">' . '<h3>' . $post_title . '</h3>' . '</div>' . '</a>' . '</article>'; } } $item_output .= '</div>'; } else { $item_output .= '<div class="no-slides-message">'; $item_output .= __('No posts added to the category slider in this category', BW_THEME); $item_output .= '</div>'; } $item_output .= '</div>'; wp_reset_postdata(); //a bit of clean up unset($post_args['meta_query']); } if ($menu_layout == 'latest_posts' || $menu_layout == 'slider_latest_posts') { $post_args['posts_per_page'] = $numberposts; $post_args['post__not_in'] = $slideposts_ids; // only posts with thumbnails //$post_args['meta_query'] = array( array( 'key' => '_thumbnail_id' ) ); $menuposts = new WP_Query($post_args); while ($menuposts->have_posts()) { $menuposts->the_post(); $post_title = get_the_title(); $post_link = get_permalink(); if (has_post_thumbnail()) { $image = Bw::get_image_src('bw_350x300'); } else { $image = BW_URI_ASSETS . 'img/empty/350x300.png'; } if ($image) { $menu_post_image = '<div class="article-thumb">'; $menu_post_image .= '<div class="image-hide"><div class="image-wrap"><img src="' . $image . '" alt="' . $post_title . '"></div></div><span class="over"></span>'; $menu_post_image .= '</div>'; } else { $menu_post_image = ''; } $item_output .= '<div class="item one-fourth">' . '<article class="article">' . '<a href="' . $post_link . '">' . $menu_post_image . '<div class="article-content"> <h2 class="article-title">' . '<span>' . $post_title . '</span>' . '</h2> <span class="small-link">' . __('Read More', BW_THEME) . '<em>+</em></span> </div> </a>' . '</article>' . '</div>'; } wp_reset_postdata(); } } } if ($depth == 0) { $item_output .= '</div>'; } // build html $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); }
break; case 'latest_by_reviews': $post_args['meta_query'] = array('relation' => 'AND', array('key' => 'enable_post_review', 'value' => '1', 'compare' => '=')); break; } $post_args['meta_query'][] = array('key' => '_thumbnail_id', 'compare' => 'EXISTS'); $slideposts = get_posts($post_args); if (count($slideposts)) { ?> <div class="billboard-posts bw-over"> <?php $c = 1; foreach ($slideposts as $post) { setup_postdata($post); $thumb_img = Bw::get_image_src($c == 1 ? 'bw_620x412' : 'bw_475x293'); if (!empty($thumb_img)) { ?> <article class="item <?php echo $c == 1 ? 'item-main' : 'item-sub'; ?> "> <a href="<?php the_permalink(); ?> "> <div class="article-thumb"> <div class="image-hide">