コード例 #1
0
 /**
  * Widget Public Display
  * -------------------------------------------------------------------------
  * @param   array     $defaults         Widget default values. 
  * @param   array     $instance         Widget instance arguments.
  */
 public function widget($defaults, $instance)
 {
     global $sections, $post;
     if (!($category = get_category($instance['category']))) {
         return;
     }
     // Widget title.
     $title = apply_filters('widget_title', $category->cat_name);
     // Transient API name.
     $trans = 'sidebar_category_posts_' . $category->slug;
     // Site section information.
     $section = kaitain_current_section_category();
     $trim = kaitain_section_css(get_the_category()[0]);
     $section_slug = $sections->get_category_section_slug(get_the_category()[0]);
     $classes = array('widget' => 'widget--sidebarcat vspace--full', 'trim_bg' => 'widget--sidebarcat__bg', 'trim_text' => $trim['texthover']);
     if ($instance['use_section_trim']) {
         // Override grey background with appropriate section trim.
         $classes['trim_bg'] = $trim['bg'];
     }
     if (!($category_posts = get_transient($trans))) {
         // Transient: fetch posts.
         $category_posts = get_posts(array('post_type' => 'post', 'post_status' => 'publish', 'numberposts' => $instance['max_posts'], 'category' => $instance['category'], 'order' => 'DESC'));
         set_transient($trans, $category_posts, get_option('kaitain_transient_timeout'));
     }
     if (!empty($defaults['before_widget'])) {
         printf($defaults['before_widget']);
     }
     // Widget interior.
     printf('<div class="%s %s">', $classes['widget'], $classes['trim_bg']);
     printf('%s<a class="%s" href="%s">%s</a>%s', $defaults['before_title'], $classes['trim_text'], get_category_link($category), $title, $defaults['after_title']);
     foreach ($category_posts as $index => $post) {
         setup_postdata($post);
         if ($instance['show_image'] && $index === 0) {
             kaitain_partial('article', 'sidebarcatlead');
         } else {
             kaitain_partial('article', 'sidebarcat');
         }
     }
     printf('</div>');
     if (!empty($defaults['after_widget'])) {
         printf($defaults['after_widget']);
     }
     wp_reset_postdata();
 }
コード例 #2
0
ファイル: single.php プロジェクト: tuairisc/kaitain
/**
 * Single Article
 * -----------------------------------------------------------------------------
 * @category   PHP Script
 * @package    Kaitain
 * @author     Mark Grealish <*****@*****.**>
 * @copyright  Copyright (c) 2014-2015, Tuairisc Bheo Teo
 * @license    https://www.gnu.org/copyleft/gpl.html The GNU GPL v3.0
 * @version    2.0
 * @link       https://github.com/bhalash/kaitain-theme
 * @link       http://www.tuairisc.ie
 */
get_header();
$trim = kaitain_current_section_css();
$section_cat = kaitain_current_section_category();
if (have_posts()) {
    while (have_posts()) {
        the_post();
        kaitain_partial('article', 'full');
        if (function_exists('rp_get_related')) {
            printf('<h4 class="%s"><a class="%s" href="%s">%s \'%s\'</a></h4>', 'subtitle related-title', $trim['texthover'], get_category_link($section_cat->cat_ID), __('Léigh tuilleadh sa rannóg seo', 'kaitain'), $section_cat->cat_name);
            printf('<div class="%s">', 'related-articles flex--three-col--article vspace--double noprint');
            $related = rp_get_related(array('range' => array('after' => date('Y-m-j') . '-21 days', 'before' => date('Y-m-j')), 'cache' => true));
            foreach ($related as $post) {
                setup_postdata($post);
                kaitain_partial('article', 'related');
            }
            printf('</div>');
            wp_reset_postdata();
        }