Example #1
0
function listable_job_listing_admin_custom_columns($column)
{
    global $post;
    switch ($column) {
        case "listable_job_position":
            echo '<div class="job_position">';
            echo '<a href="' . esc_url(admin_url('post.php?post=' . $post->ID . '&action=edit')) . '" class="tips job_title" data-tip="' . sprintf(esc_html__('ID: %d', 'listable'), $post->ID) . '">' . $post->post_title . '</a>';
            echo '<div class="company">';
            $website = esc_url(get_the_company_website());
            if ($website) {
                the_company_name('<span class="tips" data-tip="' . esc_attr($website) . '"><a href="' . $website . '">', '</a></span>');
            } else {
                the_company_name('<span class="tips" data-tip="' . esc_attr($website) . '">', '</span>');
            }
            echo '</div>';
            echo '</div>';
            break;
        case "listable_job_image":
            $company_logo_ID = listable_get_post_image_id($post->ID);
            $company_logo = '';
            if (!empty($company_logo_ID)) {
                $company_logo = wp_get_attachment_image_src($company_logo_ID);
            }
            if (!empty($company_logo) && (strstr($company_logo[0], 'http') || file_exists($company_logo[0]))) {
                $company_logo = $company_logo[0];
                $company_logo = job_manager_get_resized_image($company_logo, 'thumbnail');
                echo '<img class="company_logo" src="' . esc_attr($company_logo) . '" alt="' . esc_attr(get_the_company_name($post)) . '" />';
            }
            break;
    }
}
Example #2
0
/**
 * Return the src of the post image. In the case of listings we will try and get the first image of the gallery first, then the featured image.
 *
 * @param null $post_id
 * @param string $size
 *
 * @return bool
 */
function listable_get_post_image_src($post_id = null, $size = 'thumbnail')
{
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    $attach_id = listable_get_post_image_id($post_id);
    if (empty($attach_id) || is_wp_error($attach_id)) {
        return false;
    }
    $data = wp_get_attachment_image_src($attach_id, $size);
    // if this attachment has an url for this size, return it
    if (isset($data[0]) && !empty($data)) {
        return $data[0];
    }
    return false;
}
Example #3
0
    public function widget($args, $instance)
    {
        global $post;
        $placeholders = $this->get_placeholder_strings();
        //only put in the default title if the user hasn't saved anything in the database e.g. $instance is empty (as a whole)
        $title = apply_filters('widget_title', empty($instance) ? $placeholders['title'] : $instance['title'], $instance, $this->id_base);
        $subtitle = empty($instance) ? $placeholders['subtitle'] : $instance['subtitle'];
        $number_of_items = empty($instance['number_of_items']) ? $this->defaults['number_of_items'] : $instance['number_of_items'];
        $orderby = empty($instance['orderby']) ? $this->defaults['orderby'] : $instance['orderby'];
        $regions_slug = empty($instance['regions_slug']) ? $this->defaults['regions_slug'] : $instance['regions_slug'];
        $term_list = array();
        $custom_region_labels = array();
        //first let's do only one query and get all the terms - we will reuse this info to avoid multiple queries
        $query_args = array('order' => 'DESC', 'hide_empty' => false, 'hierarchical' => true, 'pad_counts' => true);
        if (!empty($orderby) && is_string($orderby)) {
            $query_args['orderby'] = $orderby;
        }
        $all_terms = get_terms('job_listing_region', $query_args);
        //bail if there was an error
        if (is_wp_error($all_terms)) {
            return;
        }
        //now create an array with the category slug as key so we can reference/search easier
        $all_regions = array();
        foreach ($all_terms as $key => $term) {
            $all_regions[$term->slug] = $term;
        }
        echo $args['before_widget'];
        //if we have received a list of regions to display (their slugs and optional label), use that
        if (!empty($regions_slug) && is_string($regions_slug)) {
            $regions = explode(',', $regions_slug);
            foreach ($regions as $key => $region) {
                if (strpos($region, '(') !== false) {
                    $region = explode('(', $region);
                    $term_slug = trim($region[0]);
                    if (substr($region[1], -1, 1) == ')') {
                        $custom_region_labels[$term_slug] = trim(substr($region[1], 0, -1));
                    }
                    if (array_key_exists($term_slug, $all_regions)) {
                        $term_list[] = $all_regions[$term_slug];
                    }
                } else {
                    $term_slug = trim($region);
                    if (array_key_exists($term_slug, $all_regions)) {
                        $term_list[] = $all_regions[$term_slug];
                    }
                }
            }
            //now if the user has chosen to sort these according to the number of posts, we should do that
            // since we will, by default, respect the order of the regions he has used
            if ('count' == $orderby) {
                // Define the custom sort function
                function sort_by_post_count($a, $b)
                {
                    return $a->count < $b->count;
                }
                // Sort the multidimensional array
                usort($term_list, "sort_by_post_count");
            } elseif ('rand' == $orderby) {
                //randomize things a bit if this is what the user ordered
                shuffle($term_list);
            }
        } else {
            //it seems we will have to figure out ourselves what categories to display
            if (!($number_of_items = intval($number_of_items))) {
                $number_of_items = 4;
            }
            $term_list = array_slice($all_regions, 0, $number_of_items);
        }
        if (!empty($term_list)) {
            ?>

			<h3 class="widget_title  widget_title--frontpage">
				<?php 
            echo $title;
            if (!empty($subtitle)) {
                ?>
					<span class="widget_subtitle  widget_subtitle--frontpage">
						<?php 
                echo $subtitle;
                ?>
					</span>
				<?php 
            }
            ?>
			</h3>

			<div class="categories-wrap--widget">
				<ul class="categories--widget">

					<?php 
            foreach ($term_list as $key => $term) {
                if (!$term) {
                    continue;
                }
                $icon_url = listable_get_term_icon_url($term->term_id);
                $image_url = listable_get_term_image_url($term->term_id, 'listable-card-image');
                $attachment_id = listable_get_term_icon_id($term->term_id);
                $image_src = '';
                if (!empty($image_url)) {
                    $image_src = $image_url;
                } else {
                    $thumbargs = array('posts_per_page' => 1, 'post_type' => 'job_listing', 'orderby' => 'rand', 'meta_key' => 'main_image', 'tax_query' => array(array('taxonomy' => 'job_listing_region', 'field' => 'name', 'terms' => $term->name)));
                    $latest_thumb = new WP_Query($thumbargs);
                    if ($latest_thumb->have_posts()) {
                        //get the first image in the listing's gallery or the featured image, if present
                        $image_ID = listable_get_post_image_id($latest_thumb->post->ID);
                        $image_src = '';
                        if (!empty($image_ID)) {
                            $image = wp_get_attachment_image_src($image_ID, 'medium');
                            $image_src = $image[0];
                        }
                    }
                }
                ?>

						<li <?php 
                echo empty($icon_url) ? 'class="no-icon"' : '';
                ?>
>

							<div class="category-cover" style="background-image: url(<?php 
                echo $image_src;
                ?>
)">
								<a href="<?php 
                echo esc_url(get_term_link($term));
                ?>
">
									<?php 
                if (!empty($icon_url)) {
                    ?>

										<div class="category-icon">

											<?php 
                    listable_display_image($icon_url, '', true, $attachment_id);
                    ?>

											<span class="category-count">
												<?php 
                    echo $term->count;
                    ?>
											</span>
										</div>

									<?php 
                }
                ?>

									<span class="category-text"><?php 
                echo isset($custom_region_labels[$term->slug]) ? $custom_region_labels[$term->slug] : $term->name;
                ?>
</span>
								</a>
							</div>
						</li>

					<?php 
            }
            ?>

				</ul><!-- .categories -->
			</div><!-- .categories-wrap -->
			<?php 
        }
        echo $args['after_widget'];
    }