function widget($args, $instance) { // outputs the content of the widget extract($args); $defaults = array('title' => '', 'thumb' => true, 'show' => 5); $instance = wp_parse_args($instance, $defaults); $title = apply_filters('widget_title', $instance['title']); $posts = new WP_Query(array('no_found_rows' => 1, 'post_status' => 'publish', 'posts_per_page' => $instance['show'], 'ignore_sticky_posts' => true, 'no_found_rows' => true)); // caching! if ($posts->have_posts()) { // get posts thumbnails id's $images = array(); foreach ($posts->posts as $p) { if (has_post_thumbnail($p->ID)) { $images[] = get_post_thumbnail_id($p->ID); } } // get all images in once if ($images) { $i_query = new WP_Query(array('no_found_rows' => 1, 'posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'inherit', 'post__in' => $images)); } } echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $last = $posts->found_posts; if ($posts->have_posts()) { $i = 1; foreach ($posts->posts as $post_item) { $class = ''; if ($i == 1) { $class = ' first'; } elseif ($i == $last) { $class = ' last'; } $title = get_the_title($post_item->ID); if (!$title) { $title = __('No title', LANGUAGE_ZONE); } $img = ''; if ($instance['thumb'] && has_post_thumbnail($post_item->ID)) { $img_id = get_post_thumbnail_id($post_item->ID); $img_meta = wp_get_attachment_image_src($img_id, 'full'); // get alt $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); if (!$img_alt) { $img_alt = get_the_title($post_item->ID); } $img = dt_get_thumb_img(array('alt' => $img_alt, 'img_meta' => $img_meta, 'href' => get_permalink($post_item->ID), 'thumb_opts' => array('w' => 50, 'h' => 50)), '<a %HREF% class="alignleft img-post view" ><img %SRC% %SIZE% %ALT% /></a>', false); } ?> <div class="post<?php echo $class; ?> "> <div class="post-bg"> <?php echo $img; ?> <div class="post-inner"> <a href="<?php echo get_permalink($post_item->ID); ?> "><?php echo $title; ?> </a> <div class="goto-post"> <span class="ico-link date"><?php echo get_the_date(get_option('date_format'), $post_item->ID); ?> </span> <?php dt_get_comments_link('<span class="ico-link comments">%COUNT%</span>', array('no_coments' => ''), $post_item->ID); ?> </div> </div> </div> </div> <?php $i++; } } echo $after_widget; }
function widget($args, $instance) { extract($args); /* Our variables from the widget settings. */ $defaults = array('title' => '', 'order' => 'ASC', 'show' => 6, 'orderby' => 'modified', 'select' => 'all', 'thumb' => true, 'cats' => array()); $instance = wp_parse_args((array) $instance, $defaults); $title = apply_filters('widget_title', $instance['title']); $args = array('no_found_rows' => 1, 'posts_per_page' => intval($instance['show']), 'post_status' => 'publish', 'orderby' => $instance['orderby'], 'order' => $instance['order'], 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => $instance['cats']))); switch ($instance['select']) { case 'only': $args['tax_query'][0]['operator'] = 'IN'; break; case 'except': $args['tax_query'][0]['operator'] = 'NOT IN'; break; default: unset($args['tax_query']); } add_filter('posts_clauses', 'dt_core_join_left_filter'); $query = new WP_Query($args); remove_filter('posts_clauses', 'dt_core_join_left_filter'); // caching! if ($query->have_posts()) { // get posts thumbnails id's $images = array(); foreach ($query->posts as $p) { if (has_post_thumbnail($p->ID)) { $images[] = get_post_thumbnail_id($p->ID); } } // get all images in once if ($images) { $i_query = new WP_Query(array('no_found_rows' => 1, 'posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'inherit', 'post__in' => $images)); } } if ($query->have_posts()) { echo $before_widget; // start if ($title) { echo $before_title . $title . $after_title; } $count = 0; while ($query->have_posts()) { $query->the_post(); $count++; $img = ''; if ($instance['thumb'] && has_post_thumbnail()) { $img_id = get_post_thumbnail_id(); // get alt $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); if (!$img_alt) { $img_alt = get_the_title(); } $img = dt_get_thumb_img(array('alt' => $img_alt, 'img_meta' => wp_get_attachment_image_src($img_id, 'full'), 'href' => get_permalink(), 'thumb_opts' => array('w' => 50, 'h' => 50)), '<a %HREF% class="alignleft img-post view" ><img %SRC% %SIZE% %ALT% /></a>', false); } ?> <div class="post<?php echo 1 == $count ? ' ' : ''; ?> "> <div class="post-bg"> <?php echo $img; ?> <div class="post-inner"> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> <div class="goto-post"> <span class="ico-link date"><?php echo get_the_date(get_option('date_format'), get_the_ID()); ?> </span> <?php dt_get_comments_link('<span class="ico-link comments">%COUNT%</span>', array('no_coments' => '')); ?> </div> </div> </div> </div> <?php } echo $after_widget; } wp_reset_postdata(); }
?> <div class="item-blog<?php echo $first_class; ?> "> <h2><?php echo $title; ?> </h2> <div class="entry-meta"> <?php dt_get_date_link(array('class' => 'ico-link date', 'wrap' => '<span class="%CLASS%">%DATE%</span>')); dt_get_author_link(array('class' => 'ico-link author', 'wrap' => '<span %CLASS%><a %HREF%>%AUTHOR%</a></span>')); dt_get_taxonomy_link('category', '<span class="ico-link categories">%CAT_LIST%</span>'); dt_get_comments_link($comments, array('no_coments' => '')); ?> </div> <?php if (!post_password_required($post->ID)) { if ('dt_team' !== $post->post_type && 'dt_benefits' !== $post->post_type) { dt_get_thumb_img(array('class' => 'alignleft text', 'href' => get_permalink(), 'thumb_opts' => array('w' => 210, 'h' => 210))); } dt_the_content(); dt_details_link(); dt_edit_link(); } else { echo get_the_password_form(); }
<div class="entry-meta"> <?php dt_get_date_link(array('class' => 'ico-link date', 'wrap' => '<span class="%CLASS%"><span>%DATE%</span></span>')); dt_get_author_link(array('class' => 'ico-link author', 'wrap' => '<span %CLASS%><a %HREF%>%AUTHOR%</a></span>')); dt_get_taxonomy_link('category', '<span class="ico-link categories">%CAT_LIST%</span>'); dt_get_comments_link('<span class="ico-link comments"><a href="%HREF%" class="">%COUNT%</a></span>', array('no_coments' => '')); ?> </div> <?php global $post; // thumbnail $thumb_id = get_post_thumbnail_id($post->ID); $big = wp_get_attachment_image_src($thumb_id, 'full'); $post_opts = get_post_meta($post->ID, '_dt_meta_post_options', true); if ($big && (!isset($post_opts['hide_thumb']) || !$post_opts['hide_thumb'])) { $big[3] = image_hwstring($big[1], $big[2]); $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); if (!$alt) { $alt = get_the_title(); } $thmb_args = array('w' => 210, 'h' => 210); $classes = array('alignleft', 'highslide'); $thumb_pattern = '<a class="%6$s" href="%1$s" onclick="return hs.expand(this)"><img src="%2$s" %3$s alt="%5$s" title="%4$s" /></a>'; if ('image' == get_post_format()) { $t_w = 710; $thmb_args = array('w' => $t_w); $classes[] = 'img-posts'; if ($big[1] <= $t_w) { $classes = array('alignleft');