ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

latest-news.php (8436B)


      1 <?php
      2 
      3 function materialis_companion_latest_news_excerpt_length()
      4 {
      5     return 15;
      6 }
      7 
      8 function materialis_companion_latest_news_excerpt_more()
      9 {
     10     return "[&hellip;]";
     11 }
     12 
     13 
     14 function materialis_companion_latest_news_item_meta()
     15 {
     16     ?>
     17     <a class="post-footer-link" href="<?php echo esc_url(get_permalink()); ?>">
     18         <i class="mdi small mdi-comment-outline mdc-card__action mdc-card__action--icon color-darkgray" title="Comments"></i>
     19         <span class="post-footer-value"><?php echo get_comments_number(); ?></span>
     20     </a>
     21     <a class="post-footer-link" href="<?php echo esc_url(get_permalink()); ?>">
     22         <i class="mdi small mdi-clock mdc-card__action mdc-card__action--icon color-darkgray" title="Post Time"></i>
     23         <span class="post-footer-value"><?php the_time(get_option('date_format')); ?></span>
     24     </a>
     25     <?php
     26 }
     27 
     28 function materialis_companion_latest_news_normal_item($atts)
     29 {
     30     ?>
     31     <div class="post-content no-padding <?php echo $atts['item_class']; ?>">
     32         <?php
     33         if ($atts['thumb']) : ?>
     34             <div class="">
     35                 <?php materialis_print_post_thumb(); ?>
     36             </div>
     37         <?php endif; ?>
     38 
     39         <div class="post-content-body col-padding <?php echo($atts['meta_position'] !== 'footer' || $atts['layout'] === 'list' ? 'col-no-padding-bottom' : ''); ?> ">
     40             <?php if ($atts['category'] && materialis_has_category()): ?>
     41                 <div class="space-bottom-small">
     42                     <?php materialis_the_category(); ?>
     43                 </div>
     44             <?php endif; ?>
     45 
     46             <h4 class="latest-news-item-title">
     47                 <a href="<?php the_permalink(); ?>" rel="bookmark">
     48                     <?php the_title(); ?>
     49                 </a>
     50             </h4>
     51 
     52             <?php if ($atts['meta'] && $atts['meta_position'] === 'after_title'): ?>
     53                 <div class="latest-news-item-meta after-title text-dark  space-bottom-small">
     54                     <?php materialis_companion_latest_news_item_meta(); ?>
     55                 </div>
     56             <?php endif; ?>
     57 
     58             <div class="latest-news-item-excerpt">
     59                 <?php the_excerpt(); ?>
     60             </div>
     61 
     62 
     63         </div>
     64         <?php if ($atts['meta_position'] !== 'footer' || $atts['layout'] === 'list'): ?>
     65             <div class="latest-news-item-read-more col-padding col-no-padding-bottom col-no-padding-top space-top-small space-bottom-small">
     66                 <a href="<?php esc_url(the_permalink()); ?>" class="<?php echo esc_attr($atts['readmore_class']); ?>"><?php _e('Read more', 'materialis') ?></a>
     67             </div>
     68         <?php endif; ?>
     69         <?php if ($atts['layout'] === 'cards' && $atts['meta'] && $atts['meta_position'] === 'footer'): ?>
     70             <div class="mdc-card__actions box-padding-lr-small text-dark">
     71                 <div class="mdc-card__action-icons col-xs-12 text-dark col-sm-fit no-padding-left">
     72                     <?php materialis_companion_latest_news_item_meta(); ?>
     73                 </div>
     74                 <div class="mdc-card__action-buttons col-xs-12 col-sm-fit no-padding">
     75                     <a href="<?php esc_url(the_permalink()); ?>" class="<?php echo esc_attr($atts['readmore_class']); ?>"><?php _e('Read more', 'materialis') ?></a>
     76                 </div>
     77             </div>
     78         <?php endif; ?>
     79     </div>
     80     <?php
     81 }
     82 
     83 function materialis_companion_latest_news_overlap_item($atts)
     84 {
     85     ?>
     86     <div class="post-content full-height-row flex-grow <?php echo $atts['item_class']; ?>">
     87 
     88         <div class="background-image">
     89             <?php materialis_print_post_thumb_image(); ?>
     90         </div>
     91         <div class="post-content-body col-padding bg-color-white">
     92             <?php if ($atts['category'] && materialis_has_category()): ?>
     93                 <div class="negative-margin">
     94                     <?php materialis_the_category(true); ?>
     95                 </div>
     96             <?php endif; ?>
     97             <h4 class="latest-news-item-title">
     98                 <a href="<?php the_permalink(); ?>" rel="bookmark">
     99                     <?php the_title(); ?>
    100                 </a>
    101             </h4>
    102 
    103             <?php if ($atts['meta'] && $atts['meta_position'] === 'after_title'): ?>
    104                 <div class="latest-news-item-meta after-title space-bottom-small">
    105                     <?php materialis_companion_latest_news_item_meta(); ?>
    106                 </div>
    107             <?php endif; ?>
    108 
    109             <div class="latest-news-item-excerpt">
    110                 <?php the_excerpt(); ?>
    111             </div>
    112 
    113             <div class="latest-news-item-read-mode space-top-small">
    114                 <a href="<?php esc_url(the_permalink()); ?>" class="button link color1 read-more negative-margin">
    115                     <?php _e('Read more', 'materialis') ?>
    116                     <i class="mdi mdi-arrow-right-thick"></i>
    117                 </a>
    118             </div>
    119         </div>
    120     </div>
    121     <?php
    122 }
    123 
    124 function materialis_companion_latest_news($attrs)
    125 {
    126     ob_start(); ?>
    127     <?php
    128 
    129     $atts = shortcode_atts(
    130         array(
    131             'columns'        => "4",
    132             'tablet_columns' => "6",
    133             'item_class'     => '',
    134             'readmore_class' => 'button color2 link',
    135             'posts'          => '',
    136             'advanced_mode'  => 'false',
    137 
    138             'category'      => 'yes', // none, footer, after_title
    139             'meta'          => 'yes', //  footer, after_title
    140             'meta_position' => 'footer', //  footer, after_title
    141             'thumb'         => 'yes',
    142             'spaced_posts'  => 'yes',
    143             'layout'        => 'cards', // cards, overlap, list
    144             'shadow_depth'  => '2',
    145         ),
    146         $attrs
    147     );
    148 
    149     $recentPosts = new WP_Query();
    150 
    151     $cols        = intval($atts['columns']);
    152     $tablet_cols = intval($atts['tablet_columns']);
    153 
    154     $post_numbers = ($atts['posts']) ? $atts['posts'] : 12 / $cols;
    155 
    156     add_filter('excerpt_length', 'materialis_companion_latest_news_excerpt_length');
    157     add_filter('excerpt_more', 'materialis_companion_latest_news_excerpt_more');
    158 
    159     $atts['thumb']        = materialis_to_bool($atts['thumb']);
    160     $atts['meta']         = materialis_to_bool($atts['meta']);
    161     $atts['category']     = materialis_to_bool($atts['category']);
    162     $atts['spaced_posts'] = materialis_to_bool($atts['spaced_posts']);
    163 
    164     $row_classes = array('row', 'materialis-latest-news');
    165     if ( ! $atts['spaced_posts']) {
    166         $row_classes[] = 'no-gutter-sm';
    167     }
    168 
    169     if ($atts['layout'] === 'cards') {
    170         $atts['item_class'] .= " mdc-card overflow-hidden mdc-elevation--z" . esc_attr($atts['shadow_depth']);
    171     }
    172 
    173     if ($atts['layout'] === 'overlap') {
    174         $atts['item_class'] .= " mdc-elevation--z" . esc_attr($atts['shadow_depth']);
    175     }
    176 
    177 
    178     $atts['item_class'] .= " latest-news-layout-" . esc_attr($atts['layout']);
    179 
    180     ?>
    181     <div class="<?php echo implode(" ", $row_classes); ?>">
    182         <?php
    183         $recentPosts->query('posts_per_page=' . $post_numbers . ';post_status=publish;post_type=post;ignore_sticky_posts=1;');
    184         while ($recentPosts->have_posts()):
    185             $recentPosts->the_post();
    186             if (is_sticky()) {
    187                 continue;
    188             }
    189             if ($atts['advanced_mode']) {
    190                 $categories = get_the_category();
    191             }
    192             ?>
    193             <div id="post-<?php the_ID(); ?>" class="col-sm-<?php echo $tablet_cols; ?> col-md-<?php echo $cols; ?> space-bottom space-bottom-xs">
    194                 <?php
    195                 if ($atts['layout'] === "cards" || $atts['layout'] === "list") {
    196                     materialis_companion_latest_news_normal_item($atts);
    197                 } else {
    198                     materialis_companion_latest_news_overlap_item($atts);
    199                 }
    200                 ?>
    201             </div>
    202         <?php
    203         endwhile;
    204         wp_reset_postdata();
    205         ?>
    206     </div>
    207     <?php
    208     remove_filter('excerpt_length', 'materialis_companion_latest_news_excerpt_length');
    209     remove_filter('excerpt_more', 'materialis_companion_latest_news_excerpt_more');
    210     $content = ob_get_contents();
    211     ob_end_clean();
    212 
    213     return $content;
    214 
    215 }
    216 
    217 add_shortcode('materialis_latest_news', 'materialis_companion_latest_news');