function widget($args, $instance) { extract($args); extract($instance); global $post; $title = isset($instance['title']) ? $instance['title'] : ''; $text = isset($instance['text']) ? $instance['text'] : ''; $number = empty($instance['number']) ? 4 : $instance['number']; $type = isset($instance['type']) ? $instance['type'] : 'latest'; $category = isset($instance['category']) ? $instance['category'] : ''; if ($type == 'latest') { $get_featured_posts = new WP_Query(array('posts_per_page' => $number, 'post_type' => 'post', 'ignore_sticky_posts' => true)); } else { $get_featured_posts = new WP_Query(array('posts_per_page' => $number, 'post_type' => 'post', 'category__in' => $category)); } echo $before_widget; ?> <?php if ($type != 'latest') { $border_color = 'style="border-bottom-color:' . colormag_category_color($category) . ';"'; $title_color = 'style="background-color:' . colormag_category_color($category) . ';"'; } else { $border_color = ''; $title_color = ''; } if (!empty($title)) { echo '<h3 class="widget-title" ' . $border_color . '><span ' . $title_color . '>' . esc_html($title) . '</span></h3>'; } if (!empty($text)) { ?> <p> <?php echo esc_textarea($text); ?> </p> <?php } ?> <?php $i = 1; while ($get_featured_posts->have_posts()) { $get_featured_posts->the_post(); ?> <?php if ($i == 1) { $featured = 'colormag-featured-post-medium'; } else { $featured = 'colormag-featured-post-small'; } ?> <?php if ($i == 1) { echo '<div class="first-post">'; } elseif ($i == 2) { echo '<div class="following-post">'; } ?> <div class="single-article clearfix"> <?php if (has_post_thumbnail()) { $image = ''; $title_attribute = get_the_title($post->ID); $image .= '<figure>'; $image .= '<a href="' . get_permalink() . '" title="' . the_title('', '', false) . '">'; $image .= get_the_post_thumbnail($post->ID, $featured, array('title' => esc_attr($title_attribute), 'alt' => esc_attr($title_attribute))) . '</a>'; $image .= '</figure>'; echo $image; } ?> <div class="article-content"> <?php colormag_colored_category(); ?> <h3 class="entry-title"> <a href="<?php the_permalink(); ?> " title="<?php the_title_attribute(); ?> "><?php the_title(); ?> </a> </h3> <div class="below-entry-meta"> <?php $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>'; $time_string = sprintf($time_string, esc_attr(get_the_date('c')), esc_html(get_the_date())); printf(__('<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag'), esc_url(get_permalink()), esc_attr(get_the_time()), $time_string); ?> <span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?> " title="<?php echo get_the_author(); ?> "><?php echo esc_html(get_the_author()); ?> </a></span></span> <span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link('0', '1', '%'); ?> </span> </div> <?php if ($i == 1) { ?> <div class="entry-content"> <?php the_excerpt(); ?> </div> <?php } ?> </div> </div> <?php if ($i == 1) { echo '</div>'; } ?> <?php $i++; } if ($i > 2) { echo '</div>'; } // Reset Post Data wp_reset_query(); ?> <?php echo $after_widget; }
function colormag_colored_category_title($title) { //生成子分类成导航 $obj_id = get_queried_object_id(); $cate = get_category($obj_id); if ($cate->parent > 0) { $sub_cate_id = $cate->parent; } else { $sub_cate_id = $obj_id; } $sub_cate = get_categories(array('child_of' => $sub_cate_id)); if ($sub_cate) { foreach ($sub_cate as $cate) { $sub_title .= '<span style="padding-left:10px;background:#FFF"><a href="' . get_category_link($cate->cat_ID) . '">' . $cate->cat_name . '</a></span>'; } } else { $sub_title = ''; } //echo $sub_title; $color_value = colormag_category_color(get_cat_id($title)); $color_border_value = colormag_category_color(get_cat_id($title)); if (!empty($color_value)) { return '<h1 class="page-title" style="border-bottom-color: ' . $color_border_value . '">' . '<span style="background-color: ' . $color_value . '">' . $title . '</span>' . $sub_title . '</h1>'; } else { return '<h1 class="page-title"><span>' . $title . '</span>' . $sub_title . '</h1>'; } }
function colormag_colored_category_title($title) { $color_value = colormag_category_color(get_cat_id($title)); $color_border_value = colormag_category_color(get_cat_id($title)); if (!empty($color_value)) { return '<h3 class="page-title" style="border-bottom-color: ' . $color_border_value . '">' . '<span style="background-color: ' . $color_value . '">' . $title . '</span></h3>'; } else { return '<h3 class="page-title"><span>' . $title . '</span></h3>'; } }