Beispiel #1
0
 function widget($args, $instance)
 {
     if (!empty($instance['posts'])) {
         $items = array();
         $posts = explode(',', $instance['posts']);
         srand(1);
         foreach ($posts as $p) {
             $post_thumbnail_id = get_post_thumbnail_id($p);
             $metadata = wp_get_attachment_metadata($post_thumbnail_id);
             $ratio = $metadata['width'] / $metadata['height'];
             $item = array('post_id' => $p);
             $min_i = 1;
             $min_j = 1;
             $min_error = 1;
             for ($i = 1; $i <= $instance['span']; $i++) {
                 for ($j = 1; $j <= $instance['span']; $j++) {
                     $error = abs($j * $ratio - $i);
                     if ($min_error > $error) {
                         $min_error = $error;
                         $min_i = $i;
                         $min_j = $j;
                     }
                 }
             }
             if ($min_i == $min_j) {
                 $max_size = $min_i;
                 $r = rand(1, $max_size);
                 $size = $r * $instance['size'];
                 $item['size'] = $size . 'x' . $size;
                 $item['width'] = $r;
                 $item['height'] = $r;
             } else {
                 $w = $min_i * $instance['size'];
                 $h = $min_j * $instance['size'];
                 $item['size'] = $w . 'x' . $h;
                 $item['width'] = $min_i;
                 $item['height'] = $min_j;
             }
             $items[] = $item;
         }
         wp_enqueue_script('packery');
         wp_enqueue_script('imagesloaded');
         print '<div class="widget widget-posts-packery" data-size="' . $instance['size'] . '" data-gutter="' . $instance['gutter'] . '" data-columns="' . $instance['columns'] . '">';
         print '<div class="gutter-sizer" style="width: ' . $instance['gutter'] . 'px;"></div>';
         print '<div class="grid-sizer"></div>';
         foreach ($items as $item) {
             $post = get_post($item['post_id']);
             print '<div class="item" data-width="' . $item['width'] . '" data-height="' . $item['height'] . '">';
             $image_src = azexo_get_attachment_image_src(get_post_thumbnail_id($item['post_id']), $item['size']);
             print '<div class="image" style="background-image: url(\'' . $image_src[0] . '\')"></div>';
             print '<div class="details">';
             print '<div class="title"><a href="' . esc_url(get_permalink($item['post_id'])) . '" rel="bookmark">' . get_the_title($item['post_id']) . '</a></div>';
             print '<div class="categories">' . get_the_category_list(__(', ', AZEXO_THEME_NAME), '', $item['post_id']) . '</div>';
             print '<div class="date">' . azexo_entry_date(false, $post) . '</div>';
             print '</div>';
             print '</div>';
         }
         print '</div>';
     }
 }
Beispiel #2
0
 function azexo_entry_field($template_name = 'post', $name)
 {
     $options = get_option(AZEXO_THEME_NAME);
     $output = apply_filters('azexo_entry_field', false, $template_name, $name);
     if ($output) {
         return $output;
     }
     switch ($name) {
         case 'post_sticky':
             if (is_sticky() && is_home() && !is_paged()) {
                 return '<span class="featured-post">' . __('Sticky', AZEXO_THEME_NAME) . '</span>';
             }
             break;
         case 'post_splitted_date':
             return azexo_entry_splitted_date(false);
             break;
         case 'post_date':
             return azexo_entry_date(false);
             break;
         case 'post_category':
             $categories_list = azexo_get_the_category_list(__(', ', AZEXO_THEME_NAME));
             if ($categories_list) {
                 return '<span class="categories-links">' . (isset($options[$template_name . '_category_prefix']) ? esc_html($options[$template_name . '_category_prefix']) : '') . $categories_list . '</span>';
             }
             break;
         case 'post_tags':
             $tag_list = get_the_tag_list('', __(', ', AZEXO_THEME_NAME));
             if ($tag_list) {
                 return '<span class="tags-links">' . (isset($options[$template_name . '_tags_prefix']) ? esc_html($options[$template_name . '_tags_prefix']) : '') . $tag_list . '</span>';
             }
             break;
         case 'post_author':
             if ('post' == get_post_type()) {
                 return sprintf('<span class="author vcard">' . (isset($options[$template_name . '_author_prefix']) ? esc_html($options[$template_name . '_author_prefix']) : '') . '<a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by %s', AZEXO_THEME_NAME), get_the_author())), get_the_author());
             }
             break;
         case 'post_author_avatar':
             if ('post' == get_post_type()) {
                 return '<span class="avatar">' . get_avatar(get_the_author_meta('ID')) . '</span>';
             }
             break;
         case 'post_like':
             return '<span class="like">' . getPostLikeLink(get_the_ID()) . '</span>';
             break;
         case 'post_comments_count':
             if (!is_single() && !is_search()) {
                 $comment_count = get_comment_count(get_the_ID());
                 $comments = '<a href="' . get_comments_link() . '"><span class="count">' . $comment_count['total_comments'] . '</span><span class="label">' . __('comments', AZEXO_THEME_NAME) . '</span></a>';
                 return '<span class="comments">' . $comments . '</span>';
             }
             break;
         default:
             return '';
             break;
     }
     return '';
 }