</em> </div> <?php if ($show_donation_bar) { ?> <div class="cause-info-widget-percentage"> <span><?php echo $donation_percentage; ?> %</span> <?php _e('raised of', 'dd_string'); ?> <span><?php echo $dd_donation_currency . dd_add_commas($donation_goal); ?> </span> <?php _e('goal', 'dd_string'); ?> <div class="cause-info-widget-percentage-bar" data-raised="<?php echo $donation_percentage; ?> %"> <span></span> </div><!-- .cause-info-widget-percentage-bar --> </div> <?php } ?>
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { global $dd_sn; global $dd_donation_currency; extract($args); $title = apply_filters('widget_title', $instance['title']); $amount = $instance['amount']; if (isset($instance['category'])) { $category = $instance['category']; } else { $category = 'all'; } echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } /* Start - Widget Content */ // Should funded be shown $show_funded = ot_get_option($dd_sn . 'cause_funded_show', 'enabled'); if ($show_funded == 'enabled') { $show_funded = true; } else { $show_funded = false; } if ($show_funded) { $args = array('paged' => 1, 'post_type' => 'dd_causes', 'posts_per_page' => $amount); } else { $args = array('paged' => 1, 'post_type' => 'dd_causes', 'posts_per_page' => $amount, 'meta_key' => '_dd_cause_percentage', 'order_by' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array('relation' => 'AND', array('key' => '_dd_cause_status', 'value' => 'funded', 'compare' => '!='))); } if (isset($category) && $category !== 'all') { $args['tax_query'] = array(array('taxonomy' => 'dd_causes_cats', 'field' => 'slug', 'terms' => $category)); } $widget_posts = new WP_Query($args); if ($widget_posts->have_posts()) { ?> <div class="causes-widget-carousel"> <div class="flexslider"> <ul class="slides"> <?php while ($widget_posts->have_posts()) { $widget_posts->the_post(); ?> <?php /** * Translation Sync */ $cause_id = get_the_ID(); if (defined('ICL_SITEPRESS_VERSION')) { global $dd_lang_curr; global $dd_lang_default; if ($dd_lang_curr != $dd_lang_default) { $cause_id = icl_object_id($cause_id, 'dd_causes', true, $dd_lang_default); } } $donation_goal = get_post_meta($cause_id, $dd_sn . 'cause_amount_needed', true); $donation_current = round(get_post_meta($cause_id, $dd_sn . 'cause_amount_current', true)); $show_donation_bar = true; if ($donation_goal == '' || $donation_goal == 0) { $show_donation_bar = false; } if ($donation_current == '' || $donation_current == 0) { $donation_percentage = 0; $donation_current = 0; } else { if ($show_donation_bar) { $donation_percentage = round($donation_current / $donation_goal * 100, 2); } else { $donation_percentage = '0'; } } /** * Custom Links */ $more_details_link = get_post_meta(get_the_ID(), $dd_sn . 'cause_custom_more_details_link', true); $make_donation_link = get_post_meta(get_the_ID(), $dd_sn . 'cause_custom_make_donation_link', true); if (!$more_details_link) { $more_details_link = get_permalink(); } if (!$make_donation_link) { $make_donation_link = add_query_arg('dd_donate', 'yes', get_permalink(get_the_ID())); } ?> <li class="cause <?php if ($donation_percentage >= 100) { echo 'cause-funded'; } ?> "> <div class="cause-inner"> <div class="cause-thumb"> <a href="<?php echo $more_details_link; ?> "><?php the_post_thumbnail('dd-one-third'); ?> </a> <div class="cause-thumb-overlay"> <a href="<?php echo $more_details_link; ?> " class="dd-button"><span class="icon-layout"></span><?php _e('VIEW CAUSE', 'dd_string'); ?> </a> </div><!-- cause-thumb-overlay --> </div><!-- .cause-thumb --> <div class="cause-main"> <div class="cause-meta clearfix"> <h2 class="cause-title"><a href="<?php echo $more_details_link; ?> "><?php the_title(); ?> </a></h2> <div class="cause-excerpt"> <?php the_excerpt(); ?> </div><!-- .cause-excerpt --> </div><!-- .cause-meta --> </div><!-- .cause-main --> <div class="cause-info"> <div class="cause-info-content clearfix"> <div class="fl cause-info-donated"> <span><?php echo $dd_donation_currency . dd_add_commas($donation_current); ?> </span> <?php _e('Donated', 'dd_string'); ?> </div><!-- .cause-info-donated --> <?php if ($show_donation_bar) { ?> <div class="fr cause-info-funded"> <span><?php echo $donation_percentage; ?> %</span> <?php _e('Funded', 'dd_string'); ?> </div><!-- .cause-info-funded --> <?php } ?> </div><!-- .cause-info-content --> <?php if ($show_donation_bar) { ?> <div class="cause-info-bar" data-raised="<?php echo $donation_percentage; ?> %"> <span></span> </div><!-- .cause-info-bar --> <?php } ?> <div class="cause-info-links"> <a href="<?php echo $more_details_link; ?> " class="dd-button cause-info-link-more orange-light small"><?php _e('MORE DETAILS', 'dd_string'); ?> </a> <span><?php _e('or', 'dd_string'); ?> </span> <a href="<?php echo $make_donation_link; ?> " class="dd-button cause-info-link-donate green small"><?php _e('MAKE A DONATION', 'dd_string'); ?> </a> </div><!-- .cause-info-links --> </div><!-- .cause-info --> </div><!-- .cause-inner --> </li><!-- .cause --> <?php } ?> </ul><!-- .slides --> </div><!-- .flexslider --> <div class="causes-widget-carousel-nav"> <a href="#" class="causes-widget-carousel-prev"><span class="icon-chevron-left"></span></a> <a href="#" class="causes-widget-carousel-next"><span class="icon-chevron-right"></span></a> </div><!-- .causes-widget-carousel-prev --> </div><!-- .causes-widget-carousel --> <?php } wp_reset_postdata(); /* End - Widget Content */ echo $after_widget; }
/** * Home section- Causes * * Output contents for the section on the homepage. */ function dd_home_section_causes($atts) { global $dd_sn; global $dd_donation_currency; $wrapper_class = ''; $container_class = ''; // Wrapper classes if ($atts['parity'] == 'even') { $wrapper_class .= 'even '; } else { $wrapper_class .= 'odd '; } // Container class if ($atts['type'] == 'carousel') { $container_class .= 'carousel '; } // Should funded be shown in regular listing $show_funded = ot_get_option($dd_sn . 'cause_funded_show', 'enabled'); if ($show_funded == 'enabled') { $show_funded = true; } else { $show_funded = false; } if ($show_funded) { if ($atts['category'] == 'all') { $args = array('post_type' => 'dd_causes', 'posts_per_page' => $atts['amount']); } else { $args = array('post_type' => 'dd_causes', 'posts_per_page' => $atts['amount'], 'tax_query' => array(array('taxonomy' => 'dd_causes_cats', 'field' => 'slug', 'terms' => $atts['category']))); } } else { if ($atts['category'] == 'all') { $args = array('post_type' => 'dd_causes', 'posts_per_page' => $atts['amount'], 'meta_query' => array('relation' => 'AND', array('key' => '_dd_cause_status', 'value' => 'funded', 'compare' => '!='))); } else { $args = array('post_type' => 'dd_causes', 'posts_per_page' => $atts['amount'], 'meta_query' => array('relation' => 'AND', array('key' => '_dd_cause_status', 'value' => 'funded', 'compare' => '!=')), 'tax_query' => array(array('taxonomy' => 'dd_causes_cats', 'field' => 'slug', 'terms' => $atts['category']))); } } $dd_query = new WP_Query($args); if ($dd_query->have_posts()) { $count = 0; ?> <div class="causes-wrapper home-section <?php echo $wrapper_class; ?> "> <div class="container"> <h2 class="section-title"> <?php if (!empty($atts['title'])) { ?> <span class="dd-button medium blue"><?php echo $atts['title']; ?> </span> <?php } ?> <a href="<?php echo get_permalink(dd_get_post_id('template', 'template-dd_causes.php')); ?> " class="dd-button medium orange-light"><?php _e('VIEW ALL', 'dd_string'); ?> </a> <?php if ($atts['type'] == 'carousel') { ?> <span class="carousel-nav fr"> <span class="carousel-nav-inner"> <a href="#" class="carousel-prev"></a> <a href="#" class="carousel-next"></a> </span> </span><!-- .carousel-nav --> <?php } ?> </h2> <div class="causes <?php echo $container_class; ?> clearfix" data-autoplay="<?php echo $atts['autoplay']; ?> "> <?php if ($atts['type'] == 'carousel') { ?> <div class="flexslider"> <ul class="slides"> <?php } ?> <?php while ($dd_query->have_posts()) { $dd_query->the_post(); $count++; ?> <?php if (has_post_thumbnail()) { $post_class_append = 'has-thumb '; } else { $post_class_append = ''; } /** * Translation Sync */ $cause_id = get_the_ID(); if (defined('ICL_SITEPRESS_VERSION')) { global $dd_lang_curr; global $dd_lang_default; if ($dd_lang_curr != $dd_lang_default) { $cause_id = icl_object_id(get_the_ID(), 'dd_causes', true, $dd_lang_default); } } $donation_goal = get_post_meta($cause_id, $dd_sn . 'cause_amount_needed', true); $donation_current = round(get_post_meta($cause_id, $dd_sn . 'cause_amount_current', true)); $show_donation_bar = true; if ($donation_goal == '' || $donation_goal == 0) { $show_donation_bar = false; } if ($donation_current == '' || $donation_current == 0) { $donation_percentage = 0; $donation_current = 0; } else { if ($show_donation_bar) { $donation_percentage = round($donation_current / $donation_goal * 100, 2); } else { $donation_percentage = '0'; } } /** * Custom Links */ $more_details_link = get_post_meta(get_the_ID(), $dd_sn . 'cause_custom_more_details_link', true); $make_donation_link = get_post_meta(get_the_ID(), $dd_sn . 'cause_custom_make_donation_link', true); if (!$more_details_link) { $more_details_link = get_permalink(); } if (!$make_donation_link) { $make_donation_link = add_query_arg('dd_donate', 'yes', get_permalink(get_the_ID())); } if ($atts['post_width'] == 'one_fourth') { $post_width_class = 'four columns'; $thumb_id = 'dd-home-causes'; $max_count = 4; } elseif ($atts['post_width'] == 'one_third') { $post_width_class = 'one-third column'; $thumb_id = 'dd-one-third'; $max_count = 3; } elseif ($atts['post_width'] == 'one_half') { $post_width_class = 'eight columns'; $thumb_id = 'dd-one-half'; $max_count = 2; } // Calculate last classes $last_class = ''; if ($count == $max_count) { $last_class = ' last'; $count = 0; } else { if ($count == 1) { $last_class = 'clear'; } } // If carousel clear the last classes if ($atts['type'] == 'carousel') { $last_class = ''; } ?> <li class="cause <?php echo $post_width_class . ' ' . $post_class_append . ' ' . $last_class; ?> "> <div class="cause-inner"> <div class="cause-thumb"> <a href="<?php echo $more_details_link; ?> "><?php the_post_thumbnail($thumb_id); ?> </a> </div><!-- .cause-thumb --> <div class="cause-main"> <div class="cause-meta clearfix"> <h2 class="cause-title"><a href="<?php echo $more_details_link; ?> "><?php the_title(); ?> </a></h2> <div class="cause-excerpt"> <?php the_excerpt(); ?> </div><!-- .cause-excerpt --> </div><!-- .cause-meta --> </div><!-- .cause-main --> <div class="cause-info"> <div class="cause-info-arrow"></div> <div class="cause-info-content clearfix"> <div class="fl cause-info-donated"> <span><?php echo $dd_donation_currency . dd_add_commas($donation_current); ?> </span> <?php _e('Donated', 'dd_string'); ?> </div><!-- .cause-info-donated --> <?php if ($show_donation_bar) { ?> <div class="fr cause-info-funded"> <span><?php echo $donation_percentage; ?> %</span> <?php _e('Funded', 'dd_string'); ?> </div><!-- .cause-info-funded --> <?php } ?> </div><!-- .cause-info-content --> <?php if ($show_donation_bar) { ?> <div class="cause-info-bar" data-raised="<?php echo $donation_percentage; ?> %"> <span></span> </div><!-- .cause-info-bar --> <?php } ?> <div class="cause-info-links"> <a href="<?php echo $more_details_link; ?> " class="dd-button orange-light small"><?php _e('MORE DETAILS', 'dd_string'); ?> </a> <span><?php _e('or', 'dd_string'); ?> </span> <a href="<?php echo $make_donation_link; ?> " class="dd-button green small"><?php _e('MAKE A DONATION', 'dd_string'); ?> </a> </div><!-- .cause-info-links --> </div><!-- .cause-info --> </div><!-- .cause-inner --> </li><!-- .cause --> <?php } ?> <?php if ($atts['type'] == 'carousel') { ?> </ul><!-- .slides --> </div><!-- .flexslider --> <?php } ?> </div><!-- .causes --> </div><!-- .container --> </div><!-- .causes-wrapper --> <?php } wp_reset_postdata(); }