Example #1
0
    /**
     * Widget Output
     *
     * @param $args (array)
     * @param $instance (array) Widget values.
     */
    public function widget($args, $instance)
    {
        // widget output
        extract($args);
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
        $number_of_posts = $instance['number_of_posts'];
        if (!post_type_exists('service')) {
            return false;
        }
        // Testimonials start
        $args = array('numberposts' => $number_of_posts, 'post_type' => 'service');
        $services = get_posts($args);
        $widget_body = '<section class="featured-services-widget">';
        foreach ($services as $service) {
            setup_postdata($service);
            $post_item = array('url' => $service->guid, 'content' => $service->post_content, 'title' => $service->post_title, 'image' => '', 'id' => $service->ID);
            if (has_post_thumbnail($service->ID)) {
                $post_image = wp_get_attachment_image_src(get_post_thumbnail_id($service->ID));
                $post_item['image'] = '<img src="' . $post_image[0] . '" style="width:100%;" />';
            }
            ob_start();
            ?>
         <article class="featured-service" itemscope itemtype="http://schema.org/Offer">
           <div class="service-image">
             <?php 
            echo $post_item['image'];
            ?>
           </div>
           <h4 itemprop="name"><?php 
            echo $post_item['title'];
            ?>
</h4>
           <p><?php 
            echo PLS_Format::shorten_text($post_item['content'], 130);
            ?>
</p>
           <p><a href="<?php 
            echo $post_item['url'];
            ?>
" itemprop="url">Read More</a></p>
         </article>
         <?php 
            $single_testimonial = ob_get_clean();
            /** Wrap the post in an article element and filter its contents. */
            $single_testimonial = apply_filters('pls_widget_services_post_inner', $single_testimonial, $post_item, $instance, $widget_id);
            /** Append the filtered post to the post list. */
            $widget_body .= apply_filters('pls_widget_services_post_outer', $single_testimonial, $post_item, $instance, $widget_id);
        }
        $widget_body .= '</section>';
        // Display Widget
        echo $before_widget;
        if ($instance['title']) {
            echo $before_title . $title . $after_title;
        }
        echo $widget_body;
        echo $after_widget;
    }
Example #2
0
    /**
     * Widget Output
     *
     * @param $args (array)
     * @param $instance (array) Widget values.
     */
    public function widget($args, $instance)
    {
        // widget output
        extract($args);
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
        $number_of_posts = isset($instance['number_of_posts']) ? $instance['number_of_posts'] : 5;
        $widget_id = isset($instance['widget_id']) ? $instance['widget_id'] : 1;
        /** Define the default argument array. */
        $defaults = array('before_widget' => '<section class="testimonials-widget widget">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>');
        /** Merge the arguments with the defaults. */
        $args = wp_parse_args($args, $defaults);
        extract($args, EXTR_SKIP);
        if (!post_type_exists('testimonial')) {
            return false;
        }
        // Testimonials start
        $args = array('numberposts' => $number_of_posts, 'post_type' => 'testimonial');
        $testimonials = get_posts($args);
        $widget_body = '<section class="featured-testimonials-widget">';
        foreach ($testimonials as $testimonial) {
            setup_postdata($testimonial);
            $post_item = array('url' => $testimonial->guid, 'content' => $testimonial->post_content, 'title' => $testimonial->post_title, 'image' => '', 'id' => $testimonial->ID, 'testimonial_giver' => get_post_meta($testimonial->ID, 'testimonial_giver', true), 'testimonial_giver_from' => get_post_meta($testimonial->ID, 'testimonial_giver_from', true));
            if (has_post_thumbnail($testimonial->ID)) {
                $post_image = wp_get_attachment_image_src(get_post_thumbnail_id($testimonial->ID));
                $post_item['image'] = '<img src="' . $post_image[0] . '" style="width:100%;" />';
            }
            ob_start();
            ?>
        <article class="featured-testimonial" itemscope itemtype="http://schema.org/Review">
          <h4 itemprop="name"><?php 
            echo $post_item['title'];
            ?>
</h4>
          <blockquote itemprop="review">
            <p><?php 
            echo PLS_Format::shorten_text($post_item['content'], 130);
            ?>
</p>
          </blockquote>
          <?php 
            if ($post_item['testimonial_giver']) {
                echo '<p><cite>' . $post_item['testimonial_giver'] . '</cite></p>';
            }
            ?>
          <p><a href="<?php 
            echo $post_item['url'];
            ?>
" itemprop="url">Read More</a></p>
        </article>
        <?php 
            $single_testimonial = ob_get_clean();
            /** Wrap the post in an article element and filter its contents. */
            $single_testimonial = apply_filters('pls_widget_testimonials_post_inner', $single_testimonial, $post_item, $instance, $widget_id);
            /** Append the filtered post to the post list. */
            $widget_body .= apply_filters('pls_widget_testiomonials_post_outer', $single_testimonial, $post_item, $instance, $widget_id);
        }
        $widget_body .= '</section>';
        // Display Widget
        echo $before_widget;
        if ($instance['title']) {
            echo $before_title . $title . $after_title;
        }
        echo $widget_body;
        echo $after_widget;
    }