View file StuffPost/stuffpost/parts/items.php

File size: 7.87Kb
<?php
/* Every elements witch part of the sections, only the sections.
  ToC - Table of Contents
  - Inner Post
    The post item which has contains the texts inside the featured pic.
  - Grid Post
    The post item wich has containse the texts outside the featured pic.
  - By
    The Written By badge on the items.
  - Cat
    The category bage on the items.
  - Section Title
    The title between two sections on the home or the archive pages.
 */

// INNER POST
  function weart_itemInner( $args = array() ){
    $bg = !isset($args['bg'])? 'bg-50' : $args['bg'];
    $thumb = !isset($args['thumb'])? 'weart-featured' : $args['thumb'];
    $by = !isset($args['by'])? true : $args['by'];
    $cat = !isset($args['cat'])? true : $args['cat'];
    $font = !isset($args['font'])? 'h2 f-main' : $args['font'];
    $infinite = !isset($args['infinite'])? false : $args['infinite']; ?>
      <div <?php post_class('itemInner zoom'); ?>>
        <div class="bg lazy <?php echo esc_attr($bg); ?>" data-src="<?php the_post_thumbnail_url( $thumb ); ?>" <?php if($infinite){ ?>style="background-image: url(<?php the_post_thumbnail_url( $thumb ); ?>)"<?php } ?>></div>
        <?php if($by){ weart_by(array('abs'=>'topLeft d-none d-lg-inline-block','color'=>'c-white l-white')); } ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="coverLink"></a>
        <div class="title l-white c-white">
          <div class="d-none d-md-inline-block"><?php if($cat){ weart_cat(); } ?></div>
          <h2 class="<?php echo esc_attr($font); ?>"><?php the_title(); ?></h2>
        </div>
      </div>
    <?php
  }

// GRID POST
  function weart_itemGrid( $args = array() ){
    $bg = !isset($args['bg'])? 'bg-50' : $args['bg'];
    $bg_on = !isset($args['bg_on'])? true : $args['bg_on'];
    $thumb = !isset($args['thumb'])? 'weart-featured' : $args['thumb'];
    $by = !isset($args['by'])? true : $args['by'];
    $cat = !isset($args['cat'])? true : $args['cat'];
    $font = !isset($args['font'])? 'h2 f-main' : $args['font'];
    $excerpt = !isset($args['excerpt'])? true : $args['excerpt'];
    $infinite = !isset($args['infinite'])? false : $args['infinite']; ?>
      <div <?php post_class('itemGrid'); ?>>
        <?php if($bg_on){ ?>
          <div class="zoom mb-3 <?php if( !has_post_thumbnail() ){ ?>noPostThumbnail<?php } ?>">
            <div class="bg lazy <?php echo esc_attr($bg); ?>" data-src="<?php if(has_post_thumbnail()){the_post_thumbnail_url( $thumb );} ?>" <?php if($infinite){ ?>style="background-image: url(<?php if(has_post_thumbnail()){the_post_thumbnail_url( $thumb );} ?>)"<?php } ?>>
              <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="coverLink"></a>
            </div>
            <?php if( has_post_thumbnail() ){ $color='c-white l-white'; }else{ $color='c-meta l-black'; }
            if($by){ weart_by(array('abs'=>'topLeft','color'=>$color )); } ?>
          </div>
        <?php } ?>
        <?php if($cat){ weart_cat(array('bg'=>false,'date'=>true,'color'=>'l-1 c-meta')); } ?>

        <h2 class="l-black lh-1 <?php echo esc_attr($font); ?>"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
        <?php if($excerpt){ ?>
          <?php the_excerpt(); ?>
        <?php } ?>
      </div>
    <?php
  }
// itemList
  function weart_itemList( $args = array()){
    $bg_on = !isset($args['bg_on'])? true : $args['bg_on'];
    $cat = !isset($args['cat'])? true : $args['cat'];
    $font = !isset($args['font'])? 'h6 f-main' : $args['font'];
    $circle = !isset($args['circle'])? true : $args['circle'];
    $infinite = !isset($args['infinite'])? false : $args['infinite']; ?>
    <div <?php post_class('itemList row align-items-center '); ?>>
      <?php if($bg_on && has_post_thumbnail() ){ ?>
        <div class="col-3 col-md-3">
      <div class="bg lazy bg-100 <?php if($circle){ ?>rounded-circle<?php } ?>" data-src="<?php the_post_thumbnail_url( 'weart-list' ); ?>" <?php if($infinite){ ?>style="background-image: url(<?php the_post_thumbnail_url( $thumb ); ?>)"<?php } ?>>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="coverLink"></a>
          </div>
        </div>
      <?php } ?>
      <div class="col">
        <?php if($cat){ weart_cat(array('bg'=>false,'date'=>true,'color'=>'l-1 c-meta mb-1')); } ?>
        <h2 class="l-black lh-1  <?php echo esc_attr($font); ?>"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
      </div>
    </div>
  <?php }
// BY
  function weart_by($args=array()){
    $color = !isset($args['color'])? '' : $args['color'];
    $date = !isset($args['date']) ? false : $args['date'];
    $abs = !isset($args['abs']) ? '' : $args['abs'];
    ?>
      <div class="by-badge <?php echo esc_attr($color.' '.$abs); ?> small d-flex align-items-center">
        <img src="<?php echo esc_html( get_avatar_url( get_the_author_meta('user_email'), array( 'size' => 28 )) ); ?>" class="rounded-circle mr-1" alt="" />
        <span class="author">
          <?php esc_html_e('By ','stuffpost'); the_author_posts_link() ?>
        </span>
        <?php if($date): ?>
          <span class="date">
            <?php echo esc_html( human_time_diff( get_the_time('U'), current_time('timestamp') ) ) . esc_html__(' ago', 'stuffpost'); ?>
          </span>
        <?php endif; ?>
      </div>
    <?php
  }
// CAT
  function weart_cat($args=array()){
    $bg = !isset($args['bg']) ? true : $args['bg'];
    $color = !isset($args['color']) ? '' : $args['color'];
    $date = !isset($args['date']) ? false : $args['date'];
    ?>
      <div class="cat-badge f-main border small <?php echo esc_attr($color); if(!$bg){ ?> bg-none<?php }else{?> bgh-1<?php } ?>">
        <?php the_category(', ') ?>
        <?php if($date): ?>
          <span class="date">
            <?php echo esc_html( human_time_diff( get_the_time('U'), current_time('timestamp') ) ) . esc_html__(' ago', 'stuffpost'); ?>
          </span>
        <?php endif; ?>
      </div>
    <?php
  }
// SECTION TITLE
  function weart_sectionTitle( $args = array() ){
    $title = !isset($args['title'])? '' : $args['title'];
    $font = !isset($args['font'])? '' : $args['font'];
    ?>
    <div class="container mt-5">
      <div class="row justify-content-center">
        <div class="col-lg-10 c-black mb-2">
          <div class="sectionTitle">
            <span class="bg-white h4 <?php echo esc_attr($font) ?>"><?php echo esc_attr($title) ?></span>
          </div>
        </div>
      </div>
    </div>
    <?php
  }
// NO-POSTS
  function weart_noposts(){ ?>
    <div class="col-12 py-5 my-5">
      <p class="text-center my-5">
        <span class="alert alert-danger f-title font-weight-normal">
          <?php esc_html_e('No posts are matched with the criteria.', 'stuffpost'); ?>
        </span>
      </p>
      <?php if(is_search()): ?>
        <div class="row justify-content-center">
          <div class="col-lg-6">
            <hr class="mb-5">
            <p class="small text-center"><?php esc_html_e("Try to search something else:","stuffpost") ?></p>
            <?php get_search_form() ?>
          </div>
        </div>
      <?php endif; ?>
    </div>
  <?php }
// BANNER-HOME
  function weart_bannerHome($i){ $i+=1; if( get_theme_mod('want_homeBanner_'.$i,0) && !is_paged() ){ ?>
    <div class="ad container mb-5 banner-home pb-3">
      <?php echo get_theme_mod('homeBanner_'.$i, '<img src="http://via.placeholder.com/1140x100?text='.$i.'.+position+advertise" alt="">'); ?>
    </div>
  <?php } }
// BANNER-ARTICLE
  function weart_bannerArticle(){ if(get_theme_mod('want_articleBanner',0)){ ?>
    <div class="ad my-4">
      <?php echo get_theme_mod('articleBanner', '<img src="http://via.placeholder.com/700x100?text=advertise" alt="">'); ?>
    </div>
  <?php } }