예제 #1
0
 function end_el(&$output, $item, $depth = 0, $args = array())
 {
     if ($depth == 0 && $item->object == 'category') {
         $output .= "<div class='subcat'>";
         for ($i = 0; $i < count($item->children); $i++) {
             $child = $item->children[$i];
             $output .= "<div class='" . ($i === 0 ? 'active' : '') . "' id='mn-latest-" . $child->ID . "'>";
             //$output .="<h5>".$child->title."</h5>";
             $output .= "<ul id='mn-latest-" . $child->ID . "'>";
             if ($child->object == 'category') {
                 $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => 5, 'no_found_rows' => true, 'post_status' => 'publish', 'cat' => $child->object_id)));
                 if ($r->have_posts()) {
                     while ($r->have_posts()) {
                         $r->the_post();
                         $output .= "<li ";
                         if (has_post_thumbnail()) {
                             $output .= "class='has-thumbnail' ";
                         }
                         $output .= "><div class='subcat-thumbnail'><a href='" . get_permalink() . "' title='" . get_the_title() . "'>" . get_the_post_thumbnail(get_the_ID(), array(40, 40)) . "</a></div><div class='subcat-title'><a href='" . get_permalink() . "' title='" . get_the_title() . "'> " . get_the_title() . "</a><span> - " . dw_human_time_diff(get_the_time('U'), current_time('timestamp')) . "</span></div></li>";
                     }
                     // Reset the global $the_post as this query will have stomped on it
                     wp_reset_postdata();
                 }
             }
             $output .= "</ul>";
             $output .= "<a href='" . $child->url . "' title='" . $child->attr_title . "'>View all</a>";
             $output .= "</div>";
         }
         $output .= "</div> \n</div>\n";
     } else {
     }
     $output .= "</li>\n";
 }
예제 #2
0
    function widget($args, $instance)
    {
        $cache = wp_cache_get('widget_dw_focus_recent_posts', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($args['widget_id'])) {
            $args['widget_id'] = $this->id;
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'dw_focus') : $instance['title'], $instance, $this->id_base);
        if (empty($instance['number']) || !($number = absint($instance['number']))) {
            $number = 10;
        }
        $interval = isset($instance['interval']) ? $instance['interval'] : 5;
        $categories = get_categories();
        $cats = array();
        foreach ($categories as $key => $value) {
            if ($value->parent == 0) {
                $cats[] = $value->term_id;
            }
        }
        $cat = '';
        if ($instance['category'] == 0) {
            $cat = implode(',', $cats);
        } else {
            $cat = $instance['category'];
        }
        $tax_query = array();
        $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'cat' => $cat)));
        if ($r->have_posts()) {
            $i = 0;
            //Dectect first post
            ?>
        
        <?php 
            echo $before_widget;
            ?>
        <?php 
            echo $before_title . $title . $after_title;
            ?>
        <div class="headlines" data-interval="<?php 
            echo $interval > 0 ? $interval * 1000 : 'false';
            ?>
">
            <ul>
            <?php 
            $i = 0;
            while ($r->have_posts()) {
                $r->the_post();
                ?>
                <li><a href="<?php 
                the_permalink();
                ?>
"><?php 
                the_title();
                ?>
</a><span class="time_diff"><?php 
                echo ' - ' . dw_human_time_diff(get_the_time('U'), current_time('timestamp'));
                ?>
</span></li>
            <?php 
            }
            ?>
     
            </ul>
        </div>
        <?php 
            echo $after_widget;
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_recent_posts', $cache, 'widget');
    }
예제 #3
0
 function dw_human_time()
 {
     return esc_html(dw_human_time_diff(get_the_time('c'), current_time('timestamp')));
 }