Пример #1
0
 /**
  * Add custom columns for the "manage" screen of this post type.
  *
  * @access public
  * @param string $column_name
  * @param int $id
  * @since  1.0.0
  * @return void
  */
 public function register_custom_columns($column_name, $id)
 {
     global $wpdb, $post;
     $meta = get_post_custom($id);
     switch ($column_name) {
         case 'image':
             $value = '';
             $value = projects_get_image($id, 120);
             echo $value;
             break;
         default:
             break;
     }
 }
Пример #2
0
 /**
  * Get projects.
  * @param  string/array $args Arguments to be passed to the query.
  * @since  1.0.0
  * @return array/boolean      Array if true, boolean if false.
  */
 public function get_projects($args = '')
 {
     $defaults = array('limit' => 5, 'orderby' => 'menu_order', 'order' => 'DESC', 'id' => 0);
     $args = wp_parse_args($args, $defaults);
     // Allow child themes/plugins to filter here.
     $args = apply_filters('projects_get_projects_args', $args);
     // The Query Arguments.
     $query_args = array();
     $query_args['post_type'] = 'project';
     $query_args['numberposts'] = $args['limit'];
     $query_args['orderby'] = $args['orderby'];
     $query_args['order'] = $args['order'];
     if (is_numeric($args['id']) && intval($args['id']) > 0) {
         $query_args['p'] = intval($args['id']);
     }
     // Whitelist checks.
     if (!in_array($query_args['orderby'], array('none', 'ID', 'author', 'title', 'date', 'modified', 'parent', 'rand', 'comment_count', 'menu_order', 'meta_value', 'meta_value_num'))) {
         $query_args['orderby'] = 'date';
     }
     if (!in_array($query_args['order'], array('ASC', 'DESC'))) {
         $query_args['order'] = 'DESC';
     }
     if (!in_array($query_args['post_type'], get_post_types())) {
         $query_args['post_type'] = 'project';
     }
     // The Query.
     $query = get_posts($query_args);
     // The Display.
     if (!is_wp_error($query) && is_array($query) && count($query) > 0) {
         foreach ($query as $k => $v) {
             $meta = get_post_custom($v->ID);
             // Get the image.
             $query[$k]->image = projects_get_image($v->ID, $args['size']);
             // Get the URL.
             if (isset($meta['_url'][0]) && '' != $meta['_url'][0]) {
                 $query[$k]->url = esc_url($meta['_url'][0]);
             } else {
                 $query[$k]->url = get_permalink($v->ID);
             }
         }
     } else {
         $query = false;
     }
     return $query;
 }
/**
 * Find a category image.
 * @since  1.0.0
 * @return string
 */
function projects_category_image($cat_id = 0)
{
    global $post;
    if (0 == $cat_id) {
        return;
    }
    $image = '';
    if (false === ($image = get_transient('projects_category_image_' . $cat_id))) {
        $cat = get_term($cat_id, 'project-category');
        $query_args = array('post_type' => 'project', 'posts_per_page' => -1, 'no_found_rows' => 1, 'tax_query' => array(array('taxonomy' => 'project-category', 'field' => 'id', 'terms' => array($cat->term_id))));
        $query = new WP_Query($query_args);
        while ($query->have_posts() && $image == '') {
            $query->the_post();
            $image = projects_get_image(get_the_ID());
            if ($image) {
                $image = '<a href="' . get_term_link($cat) . '" title="' . $cat->name . '">' . $image . '</a>';
                set_transient('projects_category_image_' . $cat->term_id, $image, 60 * 60);
                // 1 Hour.
            }
        }
        wp_reset_postdata();
    }
    // get transient
    return $image;
}