Guest User

Untitled

a guest
May 17th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.87 KB | None | 0 0
  1.  
  2. add_action('after_setup_theme', function() {
  3.     class avia_portfoliobox_custom extends avia_newsbox
  4.     {
  5.         function __construct()
  6.         {
  7.             $this->avia_term = 'portfolio_entries';
  8.             $this->avia_post_type = 'portfolio';
  9.  
  10.             $widget_ops = array('classname' => 'newsbox', 'description' => __('A Sidebar widget to display latest portfolio entries in your sidebar', 'avia_framework') );
  11.  
  12.             WP_Widget::__construct( 'portfolioboxnew', 'Movers Latest Portfolio', $widget_ops );
  13.         }
  14.  
  15.         function widget($args, $instance)
  16.             {
  17.                 global $avia_config;
  18.  
  19.                 extract($args, EXTR_SKIP);
  20.                 echo $before_widget;
  21.  
  22.                 $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  23.                 $count = empty($instance['count']) ? '' : $instance['count'];
  24.                 $cat = empty($instance['cat']) ? '' : $instance['cat'];
  25.                 $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt'];
  26.                 $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget';
  27.                
  28.                 $this->avia_new_query = array(  "posts_per_page"=>$count,
  29.                     'date_query' => array(
  30.                         'column' => 'post_modified',
  31.                     ),'tax_query' => array(
  32.                         array( 'taxonomy' => $this->avia_term,
  33.                             'field' => 'id',
  34.                             'terms' => explode(',', $cat),
  35.                             'operator' => 'IN')
  36.                     ));
  37.                 /**
  38.                  * @since 4.5.4
  39.                  * @return string
  40.                  */
  41.                 $image_size = apply_filters( 'avf_newsbox_image_size', $image_size, $args, $instance );
  42.  
  43.                 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  44.  
  45.  
  46.                 if(empty($this->avia_term))
  47.                 {
  48.                     $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
  49.                 }
  50.                 else
  51.                 {
  52.                     $catarray = explode(',', $cat);
  53.  
  54.  
  55.                     if(empty($catarray[0]))
  56.                     {
  57.                         $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type);
  58.                     }
  59.                     else
  60.                     {
  61.                         if($this->avia_new_query)
  62.                         {
  63.                             $new_query = $this->avia_new_query;
  64.                         }
  65.                         else
  66.                         {
  67.                             $new_query = array( "posts_per_page"=>$count, 'tax_query' => array(
  68.                                                             array( 'taxonomy' => $this->avia_term,
  69.                                                                 'field' => 'id',
  70.                                                                 'terms' => explode(',', $cat),
  71.                                                                 'operator' => 'IN')
  72.                                                                 )
  73.                                                             );
  74.                         }
  75.                     }
  76.  
  77.                     $additional_loop = new WP_Query($new_query);
  78.                 }
  79.  
  80.                 if($additional_loop->have_posts()) :
  81.  
  82.  
  83.  
  84.                 echo '<ul class="news-wrap image_size_'.$image_size.'">';
  85.                 while ($additional_loop->have_posts()) : $additional_loop->the_post();
  86.  
  87.                 $format = "";
  88.                 if(empty($this->avia_post_type))    $format = $this->avia_post_type;
  89.                 if(empty($format))                  $format = get_post_format();
  90.                 if(empty($format))                  $format = 'standard';
  91.                
  92.                 $the_id = get_the_ID();
  93.                 $link = get_post_meta( $the_id  ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : get_permalink();
  94.                
  95.                
  96.                 echo '<li class="news-content post-format-'.$format.'">';
  97.  
  98.                 //check for preview images:
  99.                 $image = "";
  100.  
  101.                 if(!current_theme_supports('force-post-thumbnails-in-widget'))
  102.                 {
  103.                     $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  104.  
  105.                     if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  106.                     {
  107.                         $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image');
  108.                     }
  109.                 }
  110.  
  111.                 if(current_theme_supports( 'post-thumbnails' ) && !$image )
  112.                 {
  113.                     $image = get_the_post_thumbnail( $the_id, $image_size );
  114.                 }
  115.  
  116.                 $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_newsbox' );
  117.  
  118.  
  119.                 echo "<a class='news-link' title='".get_the_title()."' href='".$link."'>";
  120.  
  121.                 $nothumb = (!$image) ? 'no-news-thumb' : '';
  122.  
  123.                 echo "<span class='news-thumb $nothumb'>";
  124.                 echo $image;
  125.                 echo "</span>";
  126.                 if(empty($avia_config['widget_image_size']) || 'display title and excerpt' != $excerpt)
  127.                 {
  128.                     echo "<strong class='news-headline'>".get_the_title();
  129.                    
  130.                     if($time_format)
  131.                     {
  132.                         echo "<span class='news-time'>".get_the_time($time_format)."</span>";  
  133.                     }
  134.                    
  135.                     echo "</strong>";
  136.                 }
  137.                 echo "</a>";
  138.  
  139.                 if( 'display title and excerpt' == $excerpt )
  140.                 {
  141.                     echo "<div class='news-excerpt'>";
  142.  
  143.                     if(!empty($avia_config['widget_image_size']))
  144.                     {
  145.                         echo "<a class='news-link-inner' title='".get_the_title()."' href='".$link."'>";
  146.                         echo "<strong class='news-headline'>".get_the_title()."</strong>";
  147.                         echo "</a>";
  148.                         if($time_format)
  149.                         {
  150.                             echo "<span class='news-time'>".get_the_time($time_format)."</span>";  
  151.                         }
  152.  
  153.                     }
  154.                     the_excerpt();
  155.                     echo "</div>";
  156.                 }
  157.  
  158.                 echo '</li>';
  159.  
  160.  
  161.                 endwhile;
  162.                 echo "</ul>";
  163.                 wp_reset_postdata();
  164.                 endif;
  165.  
  166.  
  167.                 echo $after_widget;
  168.  
  169.         }
  170.     }  
  171.  
  172.     register_widget( 'avia_portfoliobox_custom' );
  173. });
  174.  
Advertisement
Add Comment
Please, Sign In to add comment