function posts_list_shortcode($atts, $content = null, $shortcodename = '') { extract(shortcode_atts(array('type' => 'post', 'thumbs' => '', 'thumb_width' => '', 'thumb_height' => '', 'post_content' => '', 'numb' => '5', 'order_by' => '', 'order' => '', 'link' => '', 'link_text' => __('Read more', CHERRY_PLUGIN_DOMAIN), 'tag' => '', 'tags' => '', 'custom_class' => ''), $atts)); // check what order by method user selected switch ($order_by) { case 'date': $order_by = 'post_date'; break; case 'title': $order_by = 'title'; break; case 'popular': $order_by = 'comment_count'; break; case 'random': $order_by = 'rand'; break; } // check what order method user selected (DESC or ASC) switch ($order) { case 'DESC': $order = 'DESC'; break; case 'ASC': $order = 'ASC'; break; } global $post; global $my_string_limit_words; global $_wp_additional_image_sizes; // WPML filter $suppress_filters = get_option('suppress_filters'); $args = array('post_type' => $type, 'tag' => $tag, 'numberposts' => $numb, 'orderby' => $order_by, 'order' => $order, 'suppress_filters' => $suppress_filters); $posts = get_posts($args); $i = 0; // thumbnail size $thumb_x = 0; $thumb_y = 0; if ($thumbs == 'large') { $thumb_x = 620; $thumb_y = 300; } else { $thumb_x = $_wp_additional_image_sizes['post-thumbnail']['width']; $thumb_y = $_wp_additional_image_sizes['post-thumbnail']['height']; } // thumbnail class $thumbs_class = ''; if ($thumbs == 'large') { $thumbs_class = 'large'; } $output = '<ul class="posts-list ' . $custom_class . '">'; foreach ($posts as $key => $post) { // Unset not translated posts if (function_exists('wpml_get_language_information')) { global $sitepress; $check = wpml_get_language_information($post->ID); $language_code = substr($check['locale'], 0, 2); if ($language_code != $sitepress->get_current_language()) { unset($posts[$key]); } // Post ID is different in a second language Solution if (function_exists('icl_object_id')) { $post = get_post(icl_object_id($post->ID, $type, true)); } } setup_postdata($post); $excerpt = get_the_excerpt(); $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $url = $attachment_url['0']; if ($thumb_width != '' && $thumb_height != '') { $image = aq_resize($url, $thumb_width, $thumb_height, true); } else { $image = aq_resize($url, $thumb_x, $thumb_y, true); } $mediaType = get_post_meta($post->ID, 'tz_portfolio_type', true); $format = get_post_format(); $output .= '<li class="row-fluid list-item-' . $i . '">'; $output .= '<article class="span12 post__holder">'; //post thumbnail if (has_post_thumbnail($post->ID) && ($format == 'image' || $mediaType == 'Image')) { $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">'; $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">'; $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />'; $output .= '</a></figure>'; } elseif ($mediaType != 'Video' && $mediaType != 'Audio') { $thumbid = 0; $thumbid = get_post_thumbnail_id($post->ID); $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1)); if ($images) { $k = 0; //looping through the images foreach ($images as $attachment_id => $attachment) { $image_attributes_t = wp_get_attachment_image_src($attachment_id); // returns an array (thumbnail size) $image_attributes = wp_get_attachment_image_src($attachment_id, 'full'); // returns an array (full size) if ($thumb_width != '' && $thumb_height != '') { $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true); //resize & crop img } else { $img = aq_resize($url, $thumb_x, $thumb_y, true); } $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; if ($k == 0) { $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">'; $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">'; $output .= '<img src="' . $img . '" alt="' . get_the_title($post->ID) . '" />'; } $output .= '</a></figure>'; break; } } elseif (has_post_thumbnail($post->ID)) { $output .= '<div class="image_box">'; $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">'; $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">'; if ($thumb_width != '' && $thumb_height != '') { $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />'; } else { if ($thumbs == 'normal') { $output .= get_the_post_thumbnail($post->ID); } else { $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />'; } } $output .= '</a></figure>'; // post category $output .= '<span class="post_category">'; if ($type != '' && $type != 'post') { $terms = get_the_terms($post->ID, $type . '_category'); if ($terms && !is_wp_error($terms)) { $out = array(); foreach ($terms as $term) { $out[] = '<a href="' . get_term_link($term->slug, $type . '_category') . '">' . $term->name . '</a>'; } $output .= join(', ', $out); } } else { $categories = get_the_category(); if ($categories) { $out = array(); foreach ($categories as $category) { $out[] = '<a href="' . get_category_link($category->term_id) . '" title="' . $category->name . '">' . $category->cat_name . '</a> '; } $output .= join(', ', $out); } } $output .= '</span>'; $output .= '</div>'; } } else { // for Video and Audio post format - no lightbox $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">'; if ($thumb_width != '' && $thumb_height != '') { $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />'; } else { if ($thumbs == 'normal') { $output .= get_the_post_thumbnail($post->ID); } else { $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />'; } } $output .= '</a></figure>'; } $output .= '<h5 class="post-title"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">'; $output .= get_the_title($post->ID); $output .= '</a></h5>'; $output .= cherry_get_post_networks(array('post_id' => $post_id, 'display_title' => false, 'output_type' => 'return')); // post content if ($post_content != 'none' || $link == 'yes') { $output .= '<div class="post_content">'; switch ($post_content) { case 'excerpt': $output .= '<p class="excerpt">'; $output .= my_string_limit_words(get_the_excerpt(), 50); $output .= '</p>'; break; case 'content': $output .= '<div class="full-post-content">'; $output .= get_the_content(); $output .= '</div>'; break; case 'none': break; } // begin post meta $output .= '<span class="meta">'; $output .= '<span class="post_count">'; $output .= $icon_tips_before . custom_getPostViews($post->ID) . $icon_tips_after; $output .= '</span>'; $output .= '<span class="post-comments">'; $output .= '<a href="' . get_comments_link($post->ID) . '">'; $output .= get_comments_number($post->ID); $output .= '</a>'; $output .= '</span>'; $post_ID = get_the_ID(); $post_type = get_post_type($post_ID); $icon_tips_before = $post_meta_type == 'icon' ? '<div class="tips">' : ''; $icon_tips_after = $post_meta_type == 'icon' ? '</div>' : ''; $user_login = is_user_logged_in() ? true : false; $user_id = $user_login ? get_current_user_id() : ""; $voting_class = $user_login ? 'ajax_voting ' : 'not_voting '; $voting_url = PARENT_URL . '/includes/voting.php?post_ID=' . $post_ID . '&get_user_ID=' . $user_id; $get_voting_array = cherry_getPostVoting($post_ID, $user_id); $user_voting = $get_voting_array['user_voting']; $like_url = $user_login && $user_voting == 'none' ? 'href="' . $voting_url . '&voting=like"' : ''; $like_count = $get_voting_array['like_count']; $like_title = $user_login ? theme_locals('like') : theme_locals('not_voting'); $like_class = $user_voting == 'like' ? 'user_like ' : ''; if ($user_voting != 'none') { $voting_class = "user_voting "; } $output .= '<span class="post_like">'; $output .= '<a ' . $like_url . ' class="' . $voting_class . $like_class . '" title="' . $like_title . '" date-type="like" >'; $output .= '<i class="icon-thumbs-up"></i>'; $output .= $icon_tips_before . '<span class="voting_count">' . $like_count . '</span>' . $icon_tips_after; $output .= '</a>'; $output .= '</span>'; $output .= '</span>'; // end post meta if ($link == 'yes') { $output .= '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary" title="' . get_the_title($post->ID) . '">'; $output .= $link_text; $output .= '</a>'; } $output .= '</div>'; } //post footer if ($tags == 'yes') { $posttags = get_the_tags(); if ($posttags) { $output .= '<footer class="post_footer">' . __('Tags', CHERRY_PLUGIN_DOMAIN) . ": "; foreach ($posttags as $tag) { $output .= '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a> '; } $output .= '</footer>'; } } $output .= '</article>'; $output .= '</li><!-- .row-fluid (end) -->'; $i++; } // end foreach wp_reset_postdata(); // restore the global $post variable $output .= '</ul><!-- .posts-list (end) -->'; $output = apply_filters('cherry_plugin_shortcode_output', $output, $atts, $shortcodename); return $output; }
function get_post_metadata($args = array()) { global $global_meta_elements; if (array_key_exists('meta_elements', $args)) { $global_meta_elements = array_unique(array_merge($global_meta_elements, $args['meta_elements'])); } $meta_elements_empty = isset($args['meta_elements']) ? false : true; $defaults = array('meta_elements' => array('start_unite', 'date', 'author', 'permalink', 'end_unite', 'start_unite', 'categories', 'tags', 'end_unite', 'start_unite', 'comment', 'views', 'like', 'dislike', 'end_unite'), 'meta_class' => 'post_meta', 'meta_before' => '', 'meta_after' => '', 'display_meta_data' => true); $args = wp_parse_args($args, $defaults); $post_meta_type = of_get_option('post_meta') == 'true' || of_get_option('post_meta') == '' ? 'line' : of_get_option('post_meta'); if ($meta_elements_empty) { foreach ($global_meta_elements as $key) { if ($key != 'end_unite || start_unite') { unset($args['meta_elements'][array_search($key, $args['meta_elements'])]); } } } if ($post_meta_type != 'false' && $args['display_meta_data']) { $post_ID = get_the_ID(); $post_type = get_post_type($post_ID); $icon_tips_before = $post_meta_type == 'icon' ? '<div class="tips">' : ''; $icon_tips_after = $post_meta_type == 'icon' ? '</div>' : ''; $user_login = is_user_logged_in() ? true : false; $user_id = $user_login ? get_current_user_id() : ""; $voting_class = $user_login ? 'ajax_voting ' : 'not_voting '; $voting_url = PARENT_URL . '/includes/voting.php?post_ID=' . $post_ID . '&get_user_ID=' . $user_id; $get_voting_array = cherry_getPostVoting($post_ID, $user_id); $user_voting = $get_voting_array['user_voting']; echo $args['meta_before'] . '<div class="' . $args['meta_class'] . ' meta_type_' . $post_meta_type . '">'; foreach ($args['meta_elements'] as $value) { switch ($value) { case 'date': if (of_get_option('post_date') != 'no') { ?> <div class="post_date"> <i class="icon-calendar"></i> <?php echo $icon_tips_before . '<time datetime="' . get_the_time('Y-m-d\\TH:i:s') . '">' . get_the_date() . '</time>' . $icon_tips_after; ?> </div> <?php } break; case 'author': if (of_get_option('post_author') != 'no') { ?> <div class="post_author"> <i class="icon-user"></i> <?php echo $icon_tips_before; the_author_posts_link(); echo $icon_tips_after; ?> </div> <?php } break; case 'permalink': if (of_get_option('post_permalink') != 'no' && !is_singular()) { ?> <div class="post_permalink"> <i class="icon-link"></i> <?php echo $icon_tips_before . '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . theme_locals('permalink_to') . '</a>' . $icon_tips_after; ?> </div> <?php } break; case 'categories': if (of_get_option('post_category') != 'no') { ?> <div class="post_category"> <i class="icon-bookmark"></i> <?php echo $icon_tips_before; if ($post_type != 'post') { $custom_category = !is_wp_error(get_the_term_list($post_ID, $post_type . '_category', '', ', ')) ? get_the_term_list($post_ID, $post_type . '_category', '', ', ') : theme_locals('has_not_category'); echo $custom_category; } else { the_category(', '); } echo $icon_tips_after; ?> </div> <?php } break; case 'tags': if (of_get_option('post_tag') != 'no') { ?> <div class="post_tag"> <i class="icon-tag"></i> <?php echo $icon_tips_before; if (get_the_tags() || has_term('', $post_type . '_tag', $post_ID)) { echo $post_type != 'post' ? the_terms($post_ID, $post_type . '_tag', '', ', ') : the_tags('', ', '); } else { echo theme_locals('has_not_tags'); } echo $icon_tips_after; ?> </div> <?php } break; case 'comment': if (of_get_option('post_comment') != 'no') { ?> <div class="post_comment"> <i class="icon-comments"></i> <?php echo $icon_tips_before; comments_popup_link(theme_locals('no_comments'), theme_locals('comment'), '% ' . theme_locals('comments'), theme_locals('comments_link'), theme_locals('comments_closed')); echo $icon_tips_after; ?> </div> <?php } break; case 'views': if (of_get_option('post_views') != 'no') { ?> <div class="post_views" title="<?php echo theme_locals('number_views'); ?> "> <i class="icon-eye-open"></i> <?php echo $icon_tips_before . cherry_getPostViews($post_ID) . $icon_tips_after; ?> </div> <?php } break; case 'dislike': if (of_get_option('post_dislike') != 'no') { $dislike_url = $user_login && $user_voting == 'none' ? 'href="' . $voting_url . '&voting=dislike"' : ''; $dislike_count = $get_voting_array['dislike_count']; $dislike_title = $user_login ? theme_locals('dislike') : theme_locals('not_voting'); $dislike_class = $user_voting == 'dislike' ? 'user_dislike ' : ''; if ($user_voting != 'none') { $voting_class = "user_voting "; } ?> <div class="post_dislike"> <a <?php echo $dislike_url; ?> class="<?php echo $voting_class . $dislike_class; ?> " title="<?php echo $dislike_title; ?> " date-type="dislike" > <i class="icon-thumbs-down"></i> <?php echo $icon_tips_before . '<span class="voting_count">' . $dislike_count . '</span>' . $icon_tips_after; ?> </a> </div> <?php } break; case 'like': if (of_get_option('post_like') != 'no') { $like_url = $user_login && $user_voting == 'none' ? 'href="' . $voting_url . '&voting=like"' : ''; $like_count = $get_voting_array['like_count']; $like_title = $user_login ? theme_locals('like') : theme_locals('not_voting'); $like_class = $user_voting == 'like' ? 'user_like ' : ''; if ($user_voting != 'none') { $voting_class = "user_voting "; } ?> <div class="post_like"> <a <?php echo $like_url; ?> class="<?php echo $voting_class . $like_class; ?> " title="<?php echo $like_title; ?> " date-type="like" > <i class="icon-thumbs-up"></i> <?php echo $icon_tips_before . '<span class="voting_count">' . $like_count . '</span>' . $icon_tips_after; ?> </a> </div> <?php } break; case 'start_unite': echo '<div class="post_meta_unite clearfix">'; break; case 'end_unite': echo '</div>'; break; case 'start_group': echo '<div class="meta_group clearfix">'; break; case 'end_group': echo '</div>'; break; } } echo '</div>' . $args['meta_after']; } }